Useful Linux Commands

These Linux commands are used on an almost daily basis for any user.

Special Characters

~ represents the user’s home directory
. the current directory
.. the previous directory
| used to chain commands together

Navigating and Manipulating the File System


Print the current working directory

$ pwd


Change directory
Move to a certain directory
$ cd /public_html
Move to the directory above the current one
$ cd ..


List files and directories
Show all files and details
$ ls -la


Copy a file or directory from “source” to “target”
$ cp myfile copyoffile


Move/rename a file or directory from “source” to “target”
$ mv oldfile newfile


Remove a file
$ rm uneededfile


Make a new directory
$ mkdir newdir


Remove a directory
$ rmdir newdir


Find a file
$ find new.txt

Find all directories in /tmp that are older than 60 minutes and list them
$ find /tmp/. -maxdepth 1 -mmin +60 -type d -exec /usr/bin/ls -la {} \;

File Contents


Print the contents of a file
$ cat /logs/20190504.log


A command for perusing the contents of a file without loading the entire file into memory or locking it. Better than more
$ less /logs/20190504.log


Show the contents at the beginning of a file
To see a specific number of lines use the - parameter
$ head -50 /logs/20190504.log


Show the contents at the end of a file
To see a specific number of lines use the - parameter
$ tail -50 /logs/20190504.log
To constantly monitor the end of a file that is being written to use the -f parameter
$ tail -f /logs/20190504.log


Compare two files
$ diff thisfile thatfile


Find text in a file
$ grep 1234 /logs/20190504.log


Count the lines in a file
$ wc /logs/20190504.log


Edit a file


Bundle or Extract a bunch of files into or from a “tarball”
The -c option creates a file. The -f option specifies the name of the file. -v means verbose mode which means it prints the files
$ tar -cvf 2019/201901.tar 201901*
The -x extracts the contents to the specified location
$ tar -xvf 2019/201901.tar 2019/.


gzipCompresses a file usually containing the extension .gz
gunzipUncompresses a file usually containing the extension .gz

$ ls -lh 2019*
total 6.5M
-rw-rw-r– 1 jwolfe jwolfe 6.5M May 4 21:36 201901.tar

$ gzip 2019/201901.tar

$ ls -lh 2019*
total 676K
-rw-rw-r– 1 jwolfe jwolfe 673K May 4 21:36 201901.tar.gz


zipCompresses a file usually containing the extension .zip. gzip is much better when compressing a huge number of files.
unzipUncompresses a file usually containing the extension .zip


A network downloader
$ wget


Shows all commands that the user has entered. When the session ends, it saves the most recent 1,000 commands

Command Tools


Schedule commands to run at a specific time based on a combination of minute, hour, day of week, day of month, and month.
Option -l lists the crontab file. -e edits the crontab file
$ crontab -l
The -u option with sudo can be used to view/edit another users crontab file
$ sudo crontab -e -u jwolfe


Shows the full path of shell commands. Since the crontab file needs to have the full path for all command and files/folders, you may need to use this to find where the command is in your $PATH
$ which rm/usr/bin/rm /usr/bin/rm


Shows the full path to a shell command and any associated config or other files.
$ whereis php
php: /usr/bin/php /usr/lib64/php /etc/php.d /etc/php.ini /usr/include/php /usr/share/php /usr/share/man/man1/php.1.gz


An interface to the on-line reference manuals
$ man find



A way to make a long command shorter. Usually added the the ~/.bash_profile.
alias ll='ls -laF'


Helpful if you need to print the value of something in your session.
$ echo $PATH


show who is logged on


Shows the username that your session is currently using. Useful if you have used $ sudo su - otheruser to get to another user’s or root’s profile.


Shows the system groups that the user belongs to.

System Resources


Show file system disk space usage. Use the -h option to show the file size in human readable form.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/system-root 29G 12G 17G 41% /
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 12G 1.1G 11G 9% /run
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/sda1 497M 271M 226M 55% /boot
tmpfs 2.4G 0 2.4G 0% /run/user/0
tmpfs 2.4G 0 2.4G 0% /run/user/1000
tmpfs 2.4G 4.0K 2.4G 1% /run/user/1006


Estimate file space usage. This can be used to find which files/directories are taking up the most space
The -s option to summarize each item. The -h show the file sizes in human readable form
$ du -sh /logs/*


Display Linux Processes. Use q to close.


Display Linux Processes as top but, with better GUI, partial bottlenecks tagging and selection of multiple processes. Use F10 to close.


List all current processes that are running.
The -e option selects all processes.
The -f option does full-format listing
Count how many firefox processes are running
$ ps -ef | grep firefox | wc


Stop a running process by specifing the PID of the program (found using the ps command)
Option -15 will send the signal TERM
Option -9 will send the signal KILL
$ kill -15 34452


Show information about the system RAM. Shows total amount, used, cached, and available. Use the -h to view the data in human readable form.



Sends a signal to a remote system to see if it is responding. May be blocked by firewalls or other network settings.


Start a new session on a remote system.


Synchronize/move files between two directories. It can use SSH to connect to remote systems.
It is common to use the option -avz which preserves permission and ownership info, compresses the file during transfer and prints the files as they are moved.
The command below is commonly used to move files using the user jwolfe and log the activity.
/usr/bin/rsync -avz --remove-source-files -e "ssh -i /home/jwolfe/rsync-key" --log-file=/logs/`date +"%Y%m%d"`.log /logs/*

If you need to create a rsync connection with no password (rsync passwordless), to be use in cronjobs for instance see the following post:


Changes the user’s password.


Executes a command as the root user. Use this only when NEEDED
$ sudo systemctl restart httpd
It can be used to start a session as another user
$ sudo su - jwolfe
or as the root user
$ sudo su -


Controls system services
$ sudo systemctl restart httpd


Exits out of the current session


Shutdown the server
The -r option tells it to reboot
The first number after the options tells it how long to wait before executing.
$ sudo shutdown -r 0

Other Useful Commands

Showing Big files in a current directory
du -hs * | sort -rh | head -5

Moving files older than X days to another folder
find /from/path/ -type f -mtime +7 -exec mv "{}" /to/path/ \;