25 basic Linux commands for beginners
25 basic Linux commands for beginners
beginners
Besides being free, perhaps the command line is another important reason why lots of
people starts using Linux.
First you may feel that using command line is tough, but in reality it will take just a
day or two two get started with the linux basic commands.
Most probably you already know how to open up the terminal to type commands, so
I'm skipping this part. Let's get started.
1. 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 sub directories.
2. ls command
ls is one of the most used basic linux commands, used to print contents of a directory,
by default it lists contents of current working directory (pwd).
Page 1 sur 9
Example, use ls /usr/bin to list contents of the /usr/bin folder.
3. cd command
After knowing your pwd and getting an overview with the ls, it's time to move around
with cd command.
There's three shortcut, if you need to move one directory up, use cd .. and go
straight to your Home folder with cd, and use cd - to go back to your last working
directory.
4. cat command
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 contents of a file. As example, use cat
a_text_file to get the inside contents of that file in your screen.
5. cp command
cp , You can copy files and directories with this command. Typical usage is like cp
file_a file_1_copy or cp directory_a dir_a_copy Also don't forget to
use proper path when you're coping something to different location.
Page 2 sur 9
6. mv command
The mv command is used to move or rename directories and files. To rename a file
use mv old_name new_name, more details about mv here and here.
7. rm command
The rm command is used to remove directory or files. Like use rm -r
/tmp/backup to remove everything that folder. Of course you've to be careful
before removing anything.
8. mkdir command
mkdir, it's used to make a new directory in linux. Example, use mkdir
my_new_dir to make a new directory named my_new_directory. The -p argument
is useful, when you don't want to make parent directories manually.
9. rmdir command
rmdir, if you need to remove a directory, use this command. As example, use rmdir
my_dir to remove that specific directory. More details about the rmdir
command here.
11. ln command
This command is used to make link between files and directories. As example, you
need to make a symbolic link of the /var/www directory to the /tmp directory.
ln -s /var/www/ /tmp/
unlink /tmp/www
Page 3 sur 9
You've to be extra careful with complete path and trailing slashes while linking and
un-linking.
As example, the /var/www directory is not writable by the normal user. So to create a
blank index.html file under the /var/www directory use sudo touch
/var/www/index.html
This will print the first 20 lines of the rsyslogd log to the stdout. By default head
command prints first 10 lines.
Basically there's three type of permission, read, write and execute. Each of them
denoted by a number.
Page 4 sur 9
So if you need to set universal read/write permission to a file, you can use
chmod +x my_script_name
The long string of numbers and digits is the md5 hash of that particular file, just
match first and last two characters, that's enough.
locate -i *chromium*
18. df command
This command is used to check disk space usage on a linux system. The most
common usage is like below, used along with the -h flag.
df -h
Page 5 sur 9
19. du command
If you need to quickly check disk space usage of a file or directory, the du command
is here.
du -sh /boot/vmlinuz-4.10.10
du -sh /opt/google/chrome/
The -s flag is used to suppress unnecessary clutter and -h flag is to make the output
more human readable.
free -h
Again, the -h flag is used to make the output easier to read by humans.You can read
more here, check linux memory usage with command line tools.
Page 6 sur 9
21. zip command
No doubt you often need to create and extract zip archives, here's
the zip and unzip commands for that.
Most probably these commands are not pre-installed, install them with apt in Ubuntu.
When the -9 option is used, zip attempts maximum compression on all files and -
r option is for recursive archiving.
You might want to read about another archiving tool here, 7zip linux command
examples.
Some basic use for beginners could be like checking which network interfaces are
connected and their respective IP address.
Or you can find out how much data passed through a specific interface, all could be
done just by running the ifconfig command.
ifconfig -a
Page 7 sur 9
23. uname command
This command prints some basic information about the system, like OS name, kernel
version, host name, system time, OS architecture and so on.
uname -a
Linux acer 4.10.10 #2 SMP Mon Apr 24 00:48:20 IST 2017 x86_64
x86_64 x86_64 GNU/Linux
The above command prints everything it can, see the man page for more info.
You can also quickly find previously typed commands by pressing the Ctrl + R key
combo.
Page 8 sur 9
Almost every command has their respective man pages, useful to get a quick over
view of an unknown command, use it like man any_command .
man ifconfig
Conclusion
So that's all bout basic linux commands, hope you enjoyed this very long yet useful
tutorial.
Page 9 sur 9