The Linux command-line cheat sheet

This select set of Linux commands can help you master the command line and speed up your use of the operating system.

The Linux command-line cheat sheet
Toonzzz / Getty

When coming up to speed as a Linux user, it helps to have a cheat sheet that can help introduce you to some of the more useful commands.

In the tables below, you’ll find sets of commands with simple explanations and usage examples that might help you or Linux users you support become more productive on the command line.

Getting familiar with your account

These commands will help new Linux users become familiar with their Linux accounts.

Command Function Example
pwd Displays your current location in the file system pwd
whoami Displays your username – most useful if you switch users with su and need to be reminded what account you're using currently whoami
ls Provides a file listing. With -a, it also displays files with names starting with a period (e.g., .bashrc). With -l, it also displays file permissions, sizes and last updated date/time. ls
ls -a
ls -l
env Displays your user environment settings (e.g., search path, history size, home directory, etc.) env
echo Repeats the text you provide or displays the value of some variable echo hello
echo $PATH
history Lists previously issued commands history
history | tail -5
passwd Changes your password. Note that complexity requirements may be enforced. passwd
history | tail -5


Examining files

Linux provides several commands for looking at the content and nature of files. These are some of the most useful commands.

Command Function Example
cat Displays the entire contents of a text file. cat .bashrc
more Displays the contents of a text file one screenful at a time. Hit the spacebar to move to each additional chunk. more .bash_history
less Displays the contents of a text file one screenful at a time, but in a manner that allows you to back up using the up arrow key. less .bash_history
file Identifies files by type (e.g., ASCII text, executable, image, directory) file myfile
file ~/.bashrc
file /bin/echo


Managing files

These are some Linux commands for changing file attributes as well as renaming, moving and removing files.

Command Function Example
chmod Changes file permissions (who can read it, whether it can be executed, etc.) chmod a+x myscript
chmod 755 myscript
chown Changes file owner sudo chown jdoe myfile
cp Makes a copy of a file. cp origfile copyfile
mv Moves or renames a file – or does both mv oldname newn

To continue reading this article register now

The 10 most powerful companies in enterprise networking 2022