Linux Basic commands

ls – list directory contents

List information about the files (the current directory by default).

Options :

-a, –all : do not ignore entries starting with . (show hidden files)

-c with -lt : sort by, and show, last modification of file status information.

-h, –human-readable :Â with -l, print sizes in human readable format (e.g., 1K 234M 2G)

-l use a long listing format ( equivalent to ll command)

-r, –reverse : reverse order while sorting

-t sort by modification time

Use cases:

$ ls -lhtr

$ ls -a

$ ll

 

pwd – print name of current/working directory

Use case:

$ pwd

 

cd – Change directory

Use cases:

$ cd
$ cd ~
will always put you in your home directory.

$ cd dir
will put you in a subdirectory (dir – directory name)

$ cd ..
will move you up one directory.

$ cd ../../
will move you up two directories.

 

cp – copy files and directories

Use cases :

$ cp file.txt file_copy.txt copy file.txt contents to file_copy.txt

$ cp file.txt dir/file_copy.txt

$ cp file.txt ../../file_copy.txt

 

mv – move (rename) files

Use cases:

$ mv file.txt notes.txt

$ mv file.txt dir/subdir/notes.txt

 

touch – change file timestamps

Use cases:

$ touch file.txt

If file doen’t exists, it will create zero byte file.

 

cat – concatenate files and print on the standard output

Use cases:

$ cat files.txt
display contents for files.txt

$ cat > files.txt
Override content to files.txt

$ cat >> files.txt
Append content to files.txt

$ cat files.txt >> files2.txt copy files.txt content to files2.txt

 

mkdir – make directories

Use cases:

$ mkdir mydir
creates mydir directory

$ mkdir -p mydir/notes
creates sub directory in mydir directory

 

rm – remove files or directories

Use cases:

$ rm files.txt files2.txt
remove files

$ rm -f files.txt files.txt
remove files forcefully.

$ rm -r mydir
remove directories and their contents recursively

 

rmdir – remove empty directories

Use case:

$ rmdir dir

 

ln – make links between files

Use cases:

$ ln -s files.txt mydir/files.txt

creates symbolic link (like shortcut files in windows)

$ ln files.txt mydir/notes/files.txt

creates hard link, like another copy of file.

 

head – output the first part of files

Use cases:

$ head files.txt
outputs first 10 lines

$ head -n files.txt
outputs first n lines

 

tail – output the last part of files

Use cases:

$ tail files.txt
outputs last 10 lines

$ tail -n files.txt
outputs last n lines

$ tail -30 files.txt | head

$ head -30 files.txt | tail

 

wc – print newline, word, and byte counts for each file

Use cases:

$ wc -c files.txt
print bytes counts

$ wc -m files.txt
print characters counts

$ wc – l files.txt
print lines counts

$ wc -w files.txt
print word counts

$ wc -L files.txt
print length of the longest line

 

vi – Visual editor

Use cases:

$ vi files.txt

You we see more info in next chapter.

 

view – view files as read-only

Use case:

$ view files.txt

 

more – The more command is a “pager” utility used to view text in the terminal window one page or screen at a time.

Use case:

$ more files.txt

 

less – opposite of more

Use case

$ less files.txt

 

date – print or set the system date and time

Use case :

$ date

 

cal – displays a calendar

Use case:

$ cal

 

w – Show who is logged on and what they are doing.

Use case:

$ w

 

locate – find files by name

Use case:

$ locate files.txt

$ locate -i files.txt
ignore case

 

ps – report a snapshot of the current processes.

Use case:

$ ps -e

To see every process on the system using standard syntax

$ ps axu

To see every process on the system using BSD syntax

 

top – display Linux tasks

Use cases:

$ top
press q to quit.

 

kill – terminate a process

Use case:

$ kill pid number

 

df – report file system disk space usage

Use cases:

df -h
human readable

 

du – estimate file space usage

Use cases:

$ du -s file

display only a total for each argument

$ du -sh *

display only a total for each file in human readable.

 

free – Display amount of free and used memory in the system

Use case:

$ free

 

ssh – OpenSSH SSH client (remote login program)

Use case:

$ ssh username@remotehost

 

scp – secure copy (remote file copy program)

Use case:

$ scp files.txt user@remotehost:path

 

man – format and display the on-line manual pages

Use cases:

$ man ls

$ man scp

$ man du

 

wget – The non-interactive network downloader.

Use case:

$ wget url

 

su – substitute user

Use case:

$ su – username

substitute other user

$ su –

substitute root user

 

exit – exit or close terminal

Use case:

$ exit (CRTL -D shortcut)

 

clear – clear terminal screen

Use case:

$ clear (CTRL +L shortcut)

 

Advertisements