Main GNU/Linux commands to know when you're a beginner

I will put here the main commands to know in a GNU/Linux environment when you start with it.

PWD - Where am I?

The pwd command

To know in which path you are, you can use the pwd command.

user01@host:~$ pwd
/home/user01

Here, we can see that we are inside the user01 home directory.

Linux Directory Structure

Remember the Linux path structure (thanks to Wikipedia) and its Windows OS equivalence.

Directory Description Windows equivalence
/ root directory of the entire file system hierarchy. C:\
/bin, /sbin command binaries. C:\Program Files
/boot Boot loader files.
/dev Device files. Device Manager
/etc System configuration files. Windows Registry
/home Users' home directories. C:\Users
/root Home directory for the root user. C:\Users\Administrator
/tmp Directory for temporary files. C:\Windows\Temp
/var Variable files: files whose content is expected to continually change during normal operation of the system.

CD - Change directory

Change working directory, we can use the cd (change directory) command.

user@host:~$ cd /tmp

CP - Copy a file or a directory

Files

To copy a file or a directory we can use cp.

user@host:~$ cp my_file my_file.bak
user@host:~$ cp my_file /tmp/
user@host:~$ cp my_file my_file.bak -t /tmp/

Directories

user@host:~$ cp -r my_directory my_directory.bak

MKDIR - Create new directory

user@host:~$ mkdir my_directory

MV - Move a file or a directory

Files

To move a file or a directory we can use mv.

user@host:~$ mv my_file my_file.bak
user@host:~$ mv my_file /tmp/
user@host:~$ mv my_file my_file.bak -t /tmp/

Directories

user@host:~$ mv my_directory my_directory.bak

LS - Show files and directories

To list files we can use ls.

user@host:~$ ls
my_directory  my_directory.bak  my_file  my_file.bak
user@host:~$ ls -l
total 8192
drwxr-xr-x 2 user user      40 25 oct.  12:12 my_directory
drwxr-xr-x 2 user user      40 25 oct.  12:12 my_directory.bak
-rw-r--r-- 1 user user  8388608 25 oct.  12:12 my_file
-rw-r--r-- 1 user user        0 25 oct.  12:12 my_file.bak

You can see the d indicator for directories.

user@host:~$ ls -lh
total 8,0M
drwxr-xr-x 2 user user   40 25 oct.  12:12 my_directory
drwxr-xr-x 2 user user   40 25 oct.  12:12 my_directory.bak
-rw-r--r-- 1 user user 8,0M 25 oct.  13:22 my_file
-rw-r--r-- 1 user user    0 25 oct.  12:12 my_file.bak

RM - Remove files or directory

To remove files or directories we can use the rm command.

Be aware that there is no Recycle Bin, so once you remove files or directories, they'll be forever lost.

Files

user@host:~$ rm my_file

Directories

user@host:~$ rm -r my_directory

TAIL - Output the last part of files

Particulary useful when you want to watch real time logs.

user@host:~$ tail -f /var/log/syslog

FIND - Find files or directories

user@host:~$ find /home/user -iname '*std*'
/home/user/std
/home/user/anything_std_want
/home/user/easy_std_way
/home/user/easy_std
/home/user/anemia_std
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :