Linux commands are important for Linux beginners. This cheat sheet covers 10 basic Linux commands. It can help Linux beginners learn Linux quickly. Join our email group below. We can send you a free Linux account. You can use this account to log in to our cloud server and practice these commands.
You can also create your free Linux server on our cloud. Check more for this.
- ls command – lists contents of current working directory
- cd command – change directory
- touch command – create new file
- rm command – remove file or directory
- mkdir command – create new directory
- head command – print first few lines of a file
- tail command – print last few lines of a file
- echo command – print string
- cat command – print contents of a file
- cp command – copy file or directory
- mv command – move file or directory
pwd Command
This command prints the location of your current working directory. It’s important to know actually where you’re before going to a parent or subdirectories.
TO-M-F13P:~ root# pwd
/var/root
ls Command
ls is one of the most used basic linux commands, used to list contents of a directory, by default it lists contents of current working directory(pwd).
TO-M-F13P:~ root# ls
.CFUserTextEncoding .forward .python_history .viminfo Library
.cisco .lesshst .sh_history Application Support test
.datastax_studio .oracle_jre_usage .ssh Documents test.cap
cd command – change directory
After knowing your pwd and getting an overview with the ls, it’s time to move around with cd command. Clarification, assume you’re on your Home directory, you need to go to the /usr/local/share/fonts directory, use cd /usr/local/share/fonts.
TO-M-F13P:~ root# cd /usr/local/share/
touch command – create new file
The “touch” command is used to create new files. For example, the following command will create a new file called “/tmp/file1”:
touch /tmp/file1
If the “/tmp/file1” file already exists, the “touch” command will update the file’s modification time.
TO-M-F13P:~ root# touch howtouselinux
echo command – print string
The “echo” command is used to print text to the output. For example, the following command will print the text “Hello, world!”:
echo ‘Hello, world!’
The “echo” command can also be used to print the contents of a file. For example, the following command will print the contents of the “/etc/passwd” file:
echo ‘/etc/passwd’
cat command – print contents of a file
It’s used to print the contents of a file to the screen(stdout more precisely), really useful when you want to have a quick look on the contents of a file. It is not suitable for a large file.
TO-M-F13P:~ root# cat howtouselinux
howtouselinux
cp command – copy file or directory
cp , You can copy files and directories with this command. Typical usage is like cp file_a file_a_copy or cp dir_a dir_a_copy.
TO-M-F13P:~ root# cp howtouselinux howtouselinux_copy
TO-M-F13P:~ root# ls -lrt howtouselinux*
-rw-r–r– 1 root staff 14 Nov 7 11:39 howtouselinux
-rw-r–r– 1 root staff 14 Nov 7 11:41 howtouselinux_copy
mv command – move file or directory
The mv command is used to move or rename directories and files. To rename a file use mv old_name new_name
TO-M-F13P:~ root# mv howtouselinux howtouselinux_new
TO-M-F13P:~ root# ls -lrt howtouselinux_*
-rw-r–r–@ 1 root staff 14 Nov 7 11:39 howtouselinux_new
-rw-r–r– 1 root staff 14 Nov 7 11:41 howtouselinux_copy
rm command – remove file or directory
The rm command is used to remove directory or files. Like use rm -r /tmp/backup to remove everything that directory. Of course you’ve to be careful before removing anything.
TO-M-F13P:~ root# rm howtouselinux_new
TO-M-F13P:~ root# ls -lrt howtouselinux_*
-rw-r–r– 1 root staff 14 Nov 7 11:41 howtouselinux_cop
mkdir command – create new directory
mkdir, it’s used to make a new directory in linux. Example, use mkdir my_new_dir to create a new directory named my_new_directory. The -p argument is useful, when you don’t want to make parent directories manually.
TO-M-F13P:~ root# mkdir -p howtouselinux_dir
TO-M-F13P:~ root# ls -lrt howtouselinux_*
-rw-r–r– 1 root staff 14 Nov 7 11:41 howtouselinux_copy
drwxr-xr-x 2 root staff 68 Nov 7 11:44 howtouselinux_dir
head command – print first few lines of a file
If you need to print first few lines of a file(any type) then you can use head command. This will print the first 20 lines of the syslogd log to the stdout. By default head command prints first 10 lines.
head -20 /var/log/syslog
tail command – print last few lines of a file
It’s similar to the head command, but the function is opposite, prints last 10 lines of any file by default. Here’s an example, how to print last 30 lines of the kernel log.
tail -30 /var/log/kern.log