Useful Linux commands for beginners

What is and how to start terminal

Linux is very powerful and friendly once when you know what do you need and how to do it. I recommend you to have a small cheat sheet. This will give you confidence and will speed up your learning curve. The windows analog of terminal is Command Prompt. The difference is that Linux terminal is much more feature rich and can do almost everything.

Special symbols

  • / - root. The root folder is the parent of all other folders in Linux. You can think of it like C:/ drive in windows if you have only one drive.
  • . - A dot symbol represent current folder
  • ~ - This is used for home directory. Usually in linux the structure is :
/home/user/
/home/user1/
/home/user2/

windows equivalent would be something like:

C:\Users\user\
C:\Users\user1\
C:\Users\user2\

Shortcut

Before to start you need to launch terminal window by(depending on your distro):

  • CTRL + ALT + T - for Ubuntu and Linux Mint

  • ALT + F2 then type gnome-terminal

  • Super + T - super is windows button

  • CTRL + ALT + F1

There are several terminal types but this is not important for the new users.

You can started it also from the menu:


Linux Starter command pack

General

Do as super user:

usually when you don't have rights to do something you will get an error like this:

mv text.txt text1.txt: Permission denied

Sometimes you need administrator privileges in order to do something in linux. You can get then by several ways. On of them is to add sudo infront of the command:

sudo mv text.txt text1.txt

Log with other user:
Sometimes you need to change the logged user by(newuser is the name of the new one) :

su - newuser

See running processes:
When you are in doubt you can refer to the manual by:

top

Check used memory:
When you are in doubt you can refer to the manual by(in MBs or GBs):

free -m
free -g

Check disk space:
When you are in doubt you can refer to the manual by:

df -h

Manual:

man free

Quiting the manual and returning the shell is done by:

ALT + Q or

Super + Q - windows key and Q

Folders and Files comands

List all files in current directory:

ls

output

dev          etc          lib 

List all better format:

$ls -lh

output

dr-xr-xr-x    1 user UsersGrp       0 Jun 29 08:58 dev
drwxrwx---    1 user UsersGrp       0 Jun 26 14:30 etc
drwxrwx---    1 user UsersGrp       0 Jun 26 14:30 lib

Change folder:

cd dev

Go to previous folder

cd -

Go to root

Root in Linux is a special folder that is parent on all others. If you need to search for a file everywhere you can use root as searching point.

cd /

Create Folder in current directory:

mkdir test

Create Folder absolute path

mkdir /home/user/test

Create File

touch text.txt

Edit File

You can try one of these depending on your installed applications.

nano text.txt
vi text.txt
gedit text.txt

Delete file:

rm test.txt

Remove folder

rm -r /home/user/test

Remove all text files

rm *.txt

Remove interactive

You will be asked for confirmation prior deletion

rm -i test.txt

Copy file in current folder:

cp  file1 file2

Copy file to current folder
While "/" represents root, "." represents current folder.

cp /home/user/test.txt .

Copy with confirmation if exists

cp  -i file1 file2

Move file

mv test.txt /home/user/test

Move multiple files

mv *.txt /home/user/test

Move folder

mv test1/ /home/user/test

Renaming file

mv test.txt test_new.txt

Renaming folder

mv test/ test_new/

Find

Find for a file anywhere:
You may need to use sudo in order to search in location that you don't have rights to search.

find / -name 'test.txt'

Find in current folder:

find . -name 'test.txt'

Find using wild cards:
If you want to find all text files or file that contains some pattern

find . -name '*.txt'
find . -name '*est*'

Find in home folder:

find ~ -name 'test.txt'