Linux Commands

Notes on commands used in a terminal (shell) session. Use these in shell scripts to help unclutter and simplify your Linux usage.
Consult the man pages or Internet search for additional information on any command.


  • aplay (see also play) is a command-line audio file player for the ALSA sound card driver. It supports several file formats and multiple sound cards with multiple devices. For supported soundfile formats, the sampling rate, bit depth, and so forth can be automatically determined from the soundfile header. Syntax is aplay <soundfile>
  • cat  comes from "concatenate files and print on the standard output." It's usually used to just display the printable contents of a file, but will concatenate (join together) files if more than one filename is provided in the argument. You also can render non-printable characters with cat by using the -v option.
  • cal  prints a little text calendar in the console. Handy if you're in a non-gui ssh session. Some useful option switches are "-s" to use Sunday as the first day of the week, "-j" to display Julian dates, "-3" to span 1 month either side of the current month, and "-y" to show the whole calendar year you're in.
  • cd  changes directory to the one specified. To go up a level include ".." or "../" as the directory argument; use as many levels as you want up to the filesystem root, such as "../../../"
  • clear  clears the terminal screen, similar to clr in Windows.
  • cp copies files and directories. The options noclobber ("-n" option) and preserve permissions ("-p" option) as well as verbose ("-v" option) are handy. Use "-r" for recursive into directories.
  • cut  removes sections from each line of files. Use options for customized selections of characters, delimiters, and fields to allow outputting exactly what you want from a file.
  • date  to display the current date known by the system. Also provides several options to display the date/time in different output formats for input data to scripts.
  • df  as in "disk free" space. Use "-h" for human readable free space info. Other options to display block size and inode info.
  • du  summarizes disk usage of each FILE, recursively for directories. Use "-h" for human readable free space info. Other options to display block size and inode info.
  • firewall-cmd  Control IPTABLES. Examples: firewall-cmd --permanent --add-port=24800/tcp
    firewall-cmd --reload
  • free  to display amount of free and used memory in the system.
  • fuse (Filesystem in Userspace) is a simple interface for userspace programs to export a virtual filesystem to the Linux kernel. FUSE also aims to provide a secure method for non privileged users to create and mount their own filesystem implementations. For example, if an ssh server is running on the remote end and fuse-sshfs is installed on your client, mount a remote file share (that you have permissions to) by using this:
    sshfs <username>@<remote IP address>:<remote file share path > <local mount point> <options>
  • head  with no options prints the first 10 lines of each FILE to standard output.
  • hostname  shows or sets the system's host name. Make it permanent by editing /etc/hostname.
  • id  shows your current login real and effective user and group IDs. Useful especially if you've done su to another user.
  • ip addr add  adds an IP to an interface, leaving any other addresses on that interface active.
    Example:  sudo ip addr add <IP address/CIDR netmask> dev <interface name>.
  • ip addr del  removes an IP from an interface, leaving any other addresses on that interface active.
    Example:  sudo ip addr del <IP address/CIDR netmask> dev <interface name>.
  • ip addr show  shows all network interfaces on the machine, their IPv4 and IPv6 addresses, and other device settings such as MTU.
  • ip -o addr show  lists all network interfaces on the machine with one line (the "-o" option) for each of their IPv4 and IPv6 addresses and related address settings, but no other device settings.
  • ip -o a show | awk '/inet /{print $2":",$4}'  shows only IPv4 ("inet " with space, not "inet" to exclude "inet6") with CIDR subnet notation by piping the ip command output into awk to further filter for less cluttered reading. The $2 and $4 fields are the interface name and the IP address. The "addr" in the command is shorted to "a" to reduce further the characters typed.
  • iptraf-ng #must be run as root/sudo   is a command line utility that shows Wireshark-like network and traffic statistics in an ASCII style display in the console session from which it was launched. When the command is issued without any command-line options, the program comes up in interactive mode, with the various facilities accessed through the main menu.
  • kpartx to create device maps from partition tables. Useful in getting the offset from a raw image to loop mount it.
  • less  is a program similar to more, but which allows backward movement in the file as well as forward movement. There are several esoteric navigational options, but the most useful ones are "/<search term>" for forward searching and "?<search term>" for backward searching.
  • ln  makes links (think shortcuts) to other files. Best to use the symbolic link ("-s" option) to keep your file system less confusing by having only one hard link per file.
  • mkdir  to create directories. Use the "-p" option to make parent directories as needed below the path where you're at or have specified.
  • mount  entered as a normal user with no options shows the filesystems/partitions that are mounted on the system. Pipe into grep to find specific information you're looking for. As root you can mount other filesystems, including those in logical files already on the system as "iso" or other image files containing mountable filesystems by mounting them as "loop" devices.
  • mv  renames or moves files by changing their filenames and/or paths.
  • nmcli  manages NetworkManager settings, including adding additional IP addresses to a NIC/interface.
  • play (see also aplay) is the command-line audio file player in SoX (Sound eXchange, the Swiss Army knife of audio manipulation), Syntax is play <soundfile>
  • printf  to format and print command output, similar to echo but with more compatible options.
  • ps ax | grep -v awk | awk '/\<defunct\>/{print $1}' > pidtxt ; PIDVAR=`cat pidtxt` ; cat /proc/$PIDVAR/status | grep Pid ; rm pidtxt   shows in the resulting output a defunct (zombie) PID and its parent PID ("PPid"). If the PPid is "1" then it was likely a child process that had a parent process killed from over it, and thus init (Process 1) inherited it. If PPid is "1" the only way to be rid of that zombie PID and clean up the memory resources it's encumbering is to either let init run wait() eventually to reap out zombies, or reboot the machine. If everything else is working fine on the system, one approach is to check the next day (such as using this command) to see if the zombie PID is still there and then decide whether to reboot. (There is probably a more elegant way to do this, so suggestions are welcome!)
  • pwd  shows the current directory, think "print working directory." With the "-P" (uppercase) option, pwd shows the hard link and not a symbolic link; this is useful when you got to a directory by reaching it via "cd" through a symbolic link.
  • rmdir  to remove empty directories. (To remove directories you want gone with stuff still in them use rm -rfv <directory>, which will recursively "-r" remove everything by force "-f" whether it's empty or not, so better be really sure before using rm for this.)
  • sar -n DEV 1 100  sar is part of the sysstat set of status/monitoring utilities. In this example, it is checking network stats (the "-n" option) on all interface devices (DEV). It prints renewed output about every second, listing rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil.
  • tac  is the opposite of cat, sort of. It displays the file's whole lines in reverse order from what's in the file.
  • tail  with no options prints the last 10 lines of each FILE to standard output.
  • tar  originally came from "tape archive," but it is used with any file or storage device. Some handy uses are to combine a directory into a single file to transfer to a remote system. Use tar -cvf <source directory> <output file>.tar to create "-c" a tar file with the verbose "-v" option to view it's progress. Un-pack a tar file with tar -xvf <output file>.tar, which will extract "-x" and place all the files in their paths in a directory with the original name in the directory where you un-packed the tar file.
  • tee  is used to take piped output from a command and do something else with it while still displaying the result of the first command in stdout. For example, if you wanted to save the id information to a file while still viewing it in stdout, you would enter id | tee id.txt, which would display the id info as well as save it to id.txt.
  • udisksctl  is a command that uses the udisksd daemon to check and manage storage devices. Options include ability to show status and set up loop devices.
  • uptime  to show how long the system has been running. With no arguments, the default shows the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
  • w  to show who is logged on and what they are doing. Also includes the non-pretty uptime command output at the top of the command result.
  • wc  prints newline, word, and byte counts for each file in the argument. With no options, three numbers are displayed, one for lines, words, and bytes. It displays a total also if two or more files are parsed. Useful especially when combined with other commands in scripts.
  • who  to show quick list of who is logged on.