Unix Interview Questions – Part 1

How do you list the files in an UNIX directory while also showing hidden files?
  • ls -ltra
How do you execute a UNIX command in the background?
  • Use the “&”
What UNIX command will control the default file permissions when files are created?
  • umask
What command used to change the file permissions?
  • chmod
Explain the read, write, and execute permissions on a UNIX directory.
  • Read allows to see and list the directory contents.
  • Write allows to create, edit and delete files and subdirectories in the directory.
  • Execute gives the previous read/write permissions plus allows to change into the directory and execute programs or shells from the directory.
What is the difference between a soft link and a hard link?
  • A symbolic (soft) linked file and the targeted file can be located on the same or different file system while for a hard link they must be located on the same file system.
What is the main advantage of creating links to a file instead of copies of the file?
  • The main advantage is not really that it saves disk space (though it does that too) but, rather, that a change of permissions on the file is applied to all the link access points. The link will show permissions of lrwxrwxrwx but that is for the link itself and not the access to the file to which the link points. Thus if you want to change the permissions for a command, such as su, you only have to do it on the original. With copies you have to find all of the copies and change permission on each of the copies.
What is the command to display free disk space on the UNIX file system?
  • df -lk
What is the command to display disk usage on the UNIX file system?
  • du -a – Display an entry for each file (and not directory) contained in the current directory
Display the Disk Usage of file sizes under each directory in currentDirectory?
  • du -k * | sort -nr (or) du -k . | sort -nr
How much space is used for users in kilobytes?
  • quot -af
How would you change all occurrences of a value using VI?
  • Use :%s///g
Write a command to find all of the files which have been accessed within the last 30 days.
  • find / -type f -atime -30 > December.files &
  • This command will find all the files under root, which is ‘/’, with file type is file. ‘-atime -30′ will give all the files accessed less than 30 days ago. And the output will put into a file call December.files.
What does the following command line produce? Explain each aspect of this line.
  • $ (date ; ps -ef | awk {print $1}’ | sort | uniq | wc -l ) >> Activity.log
  • First let’s dissect the line: The date gives the date and time as the first command of the line, this is followed by the a list of all running processes in long form with UIDs listed first, this is the ps -ef. These are fed into the awk which filters out all but the UIDs; these UIDs are piped into sort for no discernible reason and then onto uniq (now we see the reason for the sort – uniq only works on sorted data – if the list is A, B, A, then A, B, A will be the output of uniq, but if it’s A, A, B then A, B is the output) which produces only one copy of each UID. These UIDs are fed into wc -l which counts the lines – in this case the number of distinct UIDs running processes on the system. Finally the results of these two commands, the date and the wc -l, are appended to the file “Activity.log”. Now to answer the question as to what this command line produces. This writes the date and time into the file Activity.log together with the number of distinct users who have processes running on the system at that time. If the file already exists, then these items are appended to the file, otherwise the file is created.


    Return to top