UNIX – Lesson 001 – pwd, df, du, w, whereis and which commands
The “pwd” returns an absolute path name of the current working directory to standard output (for example as standard output we can see the “monitor”).
DF (disk free)
The “df” command displays the amount of disk space occupied by mounted or unmounted file systems, the amount of used and available space, and how much of the file system’s total capacity has been used. The file system is specified by device, or by referring to a file or directory on the specified file system.
df [-kl] [filesystem]
- -k prints the allocation in KB
- – l reports on local filesystem only
DU (disk usage)
The “du” utility writes to standard output the size of the file space allocated to, and the size of the file space allocated to each subdirectory of, the file hierarchy rooted in each of the specified files. The size of the file space allocated to a file of type directory is defined as the sum total of space allocated to all files in the file hierarchy rooted in the directory plus the space allocated to the directory itself.
du [-sk] [name]
- -s report, instead of the default output, only the total sum for each of the specified files or the total sum for the filesystem.
- -k write the files sizes in units of 1024 bytes
# du -sk *.pdf
The “w” command displays a summary of the current activity on the system, including what each user is doing. The heading line shows the current time, the length of time the system has been up, the number of users logged into the system, and the average number of jobs in the run queue over the last 1, 5 and 15 minutes.
The fields displayed are: the user’s login name, the name of the tty the user is on, the time of day the user logged on (in hours:minutes), the idle time-that is, the number of minutes since the user last typed anything (in hours:minutes), the CPU time used by all processes and their children on that terminal (in minutes:seconds), the CPU time used by the currently active processes (in minutes:seconds), and the name and arguments of the current process.
The “whereis” utility locates source/binary and manuals sections for a command.
whereis [-bms] command
- -b Search only for binaries.
- -m Search only for manual sections.
- -s Search only for sources.
# whereis sh
sh: /sbin/sh /usr/bin/sh
# whereis perl
perl: /usr/bin/perl /usr/local/bin/perl /usr/local/bin/perl5.00503
The “which” command locates the first occurrence found in your PATH for a command.
# which sh