Hot keys and a couple of useful tricks

EnterExecutes the command.
Displays the previous command.
Ctrl+rAllows you to search for a command in history.
Ctrl+сInterrupts execution of the current command.
Ctrl+aMoves the cursor to the beginning of the line.
Ctrl+eMoves the cursor to the end of the line.
Ctrl+lClears the screen.
Ctrl+uCuts everything from the beginning of the line to the cursor and puts it in a special buffer.
Ctrl+kCuts everything from the cursor to the end of the line and puts it in a special buffer.
Ctrl+yInserts the content of a special buffer.
Ctrl+wRemoves the word/argument to the left of the cursor in the current line.
Ctrl+dTerminates the current session, similar to the exit command.
Alt+<Moves to the first command in history.
Alt+>Moves to the last command in history.
Alt+Removes everything from the beginning of the word to the cursor.
TabTabShows possible additions to the current command.
*TabTabDisplays the directories contained in the current directory (except hidden).
~TabTabDisplays a list of users from /etc/passwd.
Repeats the last command.
Combines several commands.
command | less
Displays the output of the command command page by page. You can scroll pages with Shift+ and Shift+.


All the commands described below have significantly more parameters than specified on this page. In order to get the full list of features you need the man command

man command
Displays the manual page for the command.
man -k something


apropos something
Shows the list of manual pages associated with something.

System Information

Displays the system date.
Displays the calendar for the current month.
Displays the current uptime.
Displays logged-in users.
Displays username you are logged in as.
uname -a
Displays information about the kernel.
whereis app
Shows the possible paths of the app.
which app
Shows the path by which the app will be run by default.
Displays information about HDD usage based on the file system.
df -h
Displays the same information as df, but in a more readable format (the -h flag literally means "human readable").
Displays disk usage information for each file and directory in the current directory .
Shows information about memory usage and swap.

File Commands

Listing the contents of the current directory

Displays the contents of the current directory.
ls -l
Format the output as a list with a more detailed view of the contents of the current directory.
ls -a
Also shows hidden files, respectively:
ls -la
Displays the detailed list with all the contents of the current directory.
Displays the full path to the current directory.

Displaying the file content on the screen

cat /some/file/path
Displays the content of the file /some/file/path. You can redirect the output not to the screen, but to another file, using the symbol '>'. If you want to limit the output to a certain number of lines, use the -n [number of lines] option.
Also, the cat command can be used to view specific system information, for example:
cat /proc/cpuinfo
Displays information about the CPU.
cat /proc/meminfo
Displays memory information.
more /some/file/path
Displays the content of the file /some/file/path page by page. Go to the next page with Space bar
less filename
A more advanced variation of the command more, which also paginates the contents of the file filename, but adds the ability to scroll in both directions, search for content, etc.
head -5 filename
Displays the first 5 lines of the file filename.
tail -f /some/log/path
Displays the last 10 lines of the file /some/log/path, adding new lines as they appear in the file (-f option).
tail -f /some/log/path | grep -i -P "(error|warning)"
Displays those lines from the last 10 lines of the file /some/log/path, that contain error or warning.

Change directory



cd ~
Goes to the home directory of the current user.
cd ~user
Goes to the home directory of the user.
cd /some/dir/path
Goes to the directory /some/dir/path.
cd ..
Goes to the directory one level up from the current directory (parent directory).
cd -
Returns to the previous directory.

Creating files and directories

touch filename
Creates a file named filename.
touch -t 1702270000 filename
For the file named filename changes the date and time it was created to 27.02.2017 00:00. If the file does not exist, it will be created with the specified date and time of creation (in the format YYMMDDhhmm).
mkdir dirname1
Creates a directory named dirname1.
mkdir dirname1 dirname2
Creates 2 directories at once — dirname1 and dirname2.
mkdir -p /dir1/dir2/dir3
Creates 3 directories nested into each other (creates a directory tree).
mkdir -m 755 dirname1
Creates a directory named dirname1 and sets its permissions value equal 755.

Copy, move and delete files and directories

cp /some/file/path1 /some/file/path2
Copies the file /some/file/path1 to /some/file/path2.
cp -p /some/file/path1 /some/file/path2
Copies the file /some/file/path1 to /some/file/path2 with attributes persistence (date and time modified, permissions).
cp -r /some/dir/path1 /some/dir/path2
Recursively copies the directory /some/dir/path1 to /some/dir/path2. If directory /some/dir/path2 does not exist, it will be created.
mv filename1 filename2
Renames (moves the content) of the file filename1 to filename2.
mv filename /some/dir/path
Moves the file filename to the directory /some/dir/path.
rm something
Removes the file or directory named something.
rm -r /some/dir/path
Removes the directory /some/dir/path and all of its contents (recursive deletion).

Permissions and owners

chmod mode something
Sets the permissions of the file or directory something to mode.
mode can be specified in numerical or symbolic form and defines the permissions for the owner (of the file or directory), group and all others, for example:
chmod 754 /some/dir/path


chmod rwxr-xr-- /some/dir/path
For the directory /some/dir/path sets following permissions: owner (7 in 754 case or rwx in rwxr-xr-- case) can read, write and execute (r - Read; w - Write; x - eXecute); group can read and execute; all the rest (world) can only read.
chown user:group something
For the file or directory named something assigns owner to the user user and group to group.
chmod -R 754 /some/dir/path && chown -R user:group /some/dir/path
Recursively sets the permissions and owner for the directory /some/dir/path.


find / -name dirname1 -type d
Searches for directories (-type d) named dirname1, starting with the root directory (/).
find /some/dir/path -name "*.php" -type f
Searches for all php files in the directory /some/dir/path.
find some/dir/path -type f -mtime -10
Searches for all files in the directory some/dir/path, that modified in the last 10 days.
In addition, the command find allows you to execute other commands to the files found, for example,:
find . -name "*.tmp" -type f -exec rm -rf {} \;
Searches for all tmp files in the current and child directories and deletes them.
grep "something" filename
Searches for occurrences of something in the file filename.
grep -i "something" filename1 filename2
Searches for occurrences of something in files filename1 and filename2 case insensitive (-i option).
grep --include=\*.log -r "some_ip_address" /some/dir/path
Recursively (-r option) searches for some_ip_address in all *.log files, located in the directory /some/dir/path.
history | grep "some_previous_command"
Searches for occurrences of some_previous_command in the output of the command history.
ps auxf | grep nginx
Searches for occurrences of nginx in the list of active processes (output of the command ps auxf).

Other file commands

ln filename linkname
Creates a hard link named linkname to the file filename.
ln -s /some/dir/path /some/dest/dir/path/linkname
In the directory /some/dest/dir/path/ creates symbolic link with name linkname to the directory /some/dir/path. If there are spaces in the path, they must be escaped with a backslash.
Symbolic (program, soft) links point to a file or directory but do not contain any metadata (they are somewhat similar to shortcuts in Windows). Hard links also point to the physical address of the disk area.

Working with processes

Shows the list of running processes and the resources consumed by them (CPU time, memory, etc). The information is automatically updated.
Shows the process tree.
Shows active processes.
ps auxf
Shows active processes in the form of a tree.
kill 5555


kill -TERM 5555
To the process with PID (process ID) 5555 sends signal to shutdown (-TERM).
kill -9 5555


kill -KILL 5555
To the process with PID 5555 sends signal -KILL to immediate shutdown without saving data.
lsof -p 5555
Displays the list of files opened by the process with PID 5555.

Users and Groups

useradd username
Creates an account named username.
useradd -g some_group -d /home/users/username -s /bin/bash username
Creates aa account named username, puts it into a group some_group, sets home directory as /home/users/username and appoints shell as /bin/bash.
usermod -s /bin/nologin username
Modifies attribute shell (-s option) of the account named username by setting it to /bin/nologin
userdel -r username
Removes the account named username and it's home directory.
Changes the password. For the superuser, the command passwd username, which allows you to change the password of the account named username, is available.

Other useful commands

wget -r
Recursively loads the contents of the site
wget -c
Continues to download the file filename.iso from the site
alias ngr="service nginx restart"
Assigns the command service nginx restart with the alias ngr.