Professional Documents
Culture Documents
Linux Summary
Linux Summary
Linux Summary
To open the terminal: ctrl + alt + T o Shift + ctrl + c : to copy a text inside a terminal Press the up_arrow key to see the previous commands man
To end a terminal session: ctrl + d or write : ‘exit’ o Shift + ctrl + c : to paste it (command name) to see the details
It mean : username@machinename followed by the current working directory and a dollar. If the last
character of the prompt is a pound sign (“#”) rather than (“$”) this means either we are
logged in as the root user or we selected the administrative terminal
1 – Navigation :
The first directory in the file system is called the root directory. The root directory contains files and subdirectories, which contain more files and subdirectories and so
on.
● pwd – Print name of current working directory ● ls – List directory contents
$ ls [options] [files or directory]
ls (Name of directory/folder) to see the content directory ~ : home directory ls / to
show the content of the root directory
ls .. which means that you want to print one step back directory structure
● cd – Change directory ls ../.. which means that you want to print two steps back directory structure
cd 'directory name' / cd "directory name" The most common options are :
-a: which means show the hidden folders/directories -l : list
the content directory in long format -S : list the directories
cd / we are in the root directory by their size -t : sort by modification time -h : in long format listing, display file
sizes in human-readable in bytes -r : display the results in reverse order -R : list
cd or cd ~ go to home directory subdirectories recursively -F : This option will append an indicator character to the end
of each listed name, ex: forward slash (/) if the name is a directory.
cd .. it means that we want to go to the previous directory of the
NOTE : we combine btw the options by written : ls -lSh
current working directory
ex :
cd home/lynx/test.txt
cat command
First.txt Second.txt
cat : concatenate files and print on the standard output Line 1 Line 4
$ cat [Options] [file1 file2 file3...] Line 2 Line 5
Line 3 Line 6
1-diplay the content of text file or multiple files 2- Redirection : it means capturing output from a file
command or program and sending it as an input to another file command or
Ex : cat First.txt program
Line 1
First option: if u want to transfer some output and redirect it to a file
Line 2 SYNTAX: cat output > file
Line 3 ex : cat > test.txt
Options : hmmmmm
it working
line 2
line 3
-IF we want to append a text to the existing content of a file just write this command
ex : cat >> test.txt let's show the result after the appending :
Ex : pwd Ex : pwd
Home/Lynx/Desktop Home/Lynx/Desktop
mkdir Test1 Test2 mkdir -p a/b/c/d
rm : $ rm [-Options] [Directory_name]
ls ls
Test1 Test2 a Test1 rm options :
rmdir Test2 ls -R
ls a Test1
Test 1 .:
a
let's create a directories
./a:
structure
b
pwd ./a/b:
Home/Lynx/Desktop c
mkdir -p a/b/c/d ./a/b/c:
ls d Ex :
a Test1 ./a/b/c/d:
ls -R cd a/b
a Test1 cat > text_file.txt
.: keep going
a ./ rmdir -pv a/b/c/d
a: rmdir: removing directory, 'a/b/c/d'
b rmdir: removing directory, 'a/b/c'
rmdir: removing directory, 'a/b'
./a/b:
rmdir: failed to remove directory 'a/b':
c
Directory not empty
./a/b/c:
ls -R
d N.B :
.: Ex :
./a/b/c/d: we see that a/b doesn't
a Test1 rm -rv a
rmdir -p a/b/c/d removed cuz b contain a
.a: rmdir: removing directory, 'a/b/text_file.txt'
ls file
b rmdir: removing directory, 'a/b/'
Test1 so we'll use rm command
.b: rmdir: removing directory, 'a'
text_file.txt
cp command
cp : copy
$ cp [options] [name or location of your source directory] [destination/absolute path or relative path]
(absolute path : the entire path beginning from the root directory. Ex: /home/lynx/Documents
whereas relative path begins from the current working directory. Ex : Documents)
Ex 3: (if u wanna copy the two files into dir1 but the file 'Serie2.txt' is already
Ex 5: pwd
existing there so this command will overwrite the content of 'Serie2.txt')
home/lynx/Desktop
pwd
ls
home/lynx/Desktop
dir3
ls
cp dir3 dir4 (it works if the dir3 was empty)
Serie1.txt Serie2.txt dir1 dir2 Serie1_cp.txt
ls
cp Serie1.txt Serie2.txt dir1
dir3 dir4
*To avoid the overwriting just add this flag(option) in your command : -i
which stands for interactive interface so will ask you before overwriting cp -vr dir3 dir4
pwd
(it works if the dir3 was not empty so the content of dir3 will copy to the
home/lynx/Desktop
dir 4 without the dir3 cuz dir4 doesn't exist )
ls
-r means the recursive copying
Serie1.txt Serie2.txt dir1 dir2 Serie1_cp.txt
-v means verbose (explain what is being done)
cp -i Serie1.txt Serie2.txt dir1
cp: overwrite 'dir1/Serie2.txt'? (Y :yes/N :no)
Ex : (copy a multiple file)
Ex 4: pwd pwd
home/lynx/Desktop/dir1 home/lynx/Desktop
ls ls
Serie1.txt Serie2.txt Serie1.txt Serie2.txt dir1 dir2 Serie1_cp.txt
cp ../Serie1_cp.txt . ('.' represents the current working directory cp Serie1.txt Serie2.txt dir2
(it's going to copy the file to the directory) ls dir2
Serie1.txt Serie2.txt (the files are copied in dir2)
mv command
mv : is used to move a source file to given destination / (Move/rename files and directories)
$ mv [options] [name or location of your source directory] [destination/absolute path or relative path]
Sum :
mv file1 file2 // will over write file2 with file1 if the file exist otherwise will create a new file
mv -i file1 file2 // -i stands for interactive which will ask before overwriting file
mv dir1 dir2 //to move dir1 inside dir2 with her content along it if dir2 exist otherwise only content
Less command Touch command
less : is used to see the file contents from the starting/Read the file or search touch: The touch command is usually used to set or update the access, change,and
something inside it modify timestep of file or directory. However, if a filename argument is that of a non-
$ less [options] [file] existent file, an empty file (like .txt /.cpp or simple file) is created.
The most common keyboard commands used by less : $ touch [options] [file]
. Timestamp the time of create or update the file .
nano command
nano : is used for creating and editing text files directly from the command line. The nano interface :
$ nano or $ nano [options]
Features:
Easy-to-Use Interface: Nano provides a straightforward and beginner-friendly text-
based interface.
Syntax Highlighting: Nano supports syntax highlighting for various programming
languages, making code easier to read.
Search and Replace: Users can search for specific text strings and replace them within
the file.
Line Numbers: Line numbers are displayed for easy navigation.
Basic Usage:
Open a file: nano filename Save changes: Press Ctrl+O, then Enter.
Exit nano: Press Ctrl+X. Ctrl+K (cut), Ctrl+U (uncut/paste), and Ctrl+Shift+6 (copy).
sudo command
Ex 1: cd / Ex 2: sudo -s
cd etc [sudo] password for lynx :
mkdir new_file sudo : (super user do) Execute a command as another user root/machine_name/etc#
erreur : Permission denied $ sudo [command] we’re in super user mode
sudo mkdir new_file
[sudo] password for lynx :
top command
top : (Display Linux processes) /is used to view the CPU usage of all processes.for ex if u wanna know which process is taking
most of your CPU or which program is taking most of your computer memory
$ top
kill : is used to “kill” processes. This allows us to terminate programs that need killing (that is, some kind of pausing or termination). The command uses one or more
PID’s as its argument $ kill <PID of the program> or $ kill [Option] <PID of a process>
-The PID of a program is changing after the killing process
-To kill a process by force : $ kill -KILL <PID>
Ps : is used to display the process status .submission time, required CPU time , sleep : it will suspend the execution of shell. The maximum limit of sleep is
Process name (u can see the name of process and their ID) 18000 s,Unfortunately keep the terminal idle.
$ ps [Option]
$ Sleep [time in second]
PS options : -a Print all terminal process
-e Print all current process
-t Print all processes of listed terminal
-u Displays processes of listed user
echo command
echo : (Display a line of text) is a shell built-in that performs a very Ex : (echoing a text) Ex : (create a var and display it) Ex : (create a var and display it)
simple task. It prints its text arguments on standard output. echo ‘’Hello world’’ age=20 age=20 name=’’LYNX’’
$ echo [ Option ] [str,var…..] Hello world echo $age echo ‘’My name’s $name and I’ve $age
20 years old’’
-All var are valid for the session of the terminal when u’re close the echo ‘’I’ve $age years old’’ My name’s LYNX and I’ve 20 years old
terminal the var will be gone. I’ve 20 years old
Escaping Characters : Adding the -e option to echo will enable interpretation of escape sequences. You may also place them inside $' '.
Ex 1: id id : (Display user identity) it means : Print user and group info for each specified Ex 2: id -u
uid=1000(lynx) gid=1000(lynx) USER, or (when USER omitted) for the current user. 1000
groups=1000(lynx),4(adm),24(cdrom), $ id or $ id [Option] <username>
27(sudo),30(dip),46(plugdev) Options : id -g
-g Print only the effective group ID 1000
uid user id -G Print all group IDs
gid group id -u Print only the effective user ID id -G
-r Print the real ID instead of the effective ID, with -ugG 1000 4 24 27 30 46
-n Print a name instead of a number, for -ugG
Access rights to files and directories are defined in terms of read access, write
access, and execution access
EX : cd home/lynx/desktop
ls -l file.txt
-rw-rw-r-- 1 lynx lynx 49 Jan 29 11:04 file.txt
The first character is the file type: The nine characters are the file mode:
- a regular file
d a directory
l a symbolic link
The read,write,execute permissions for
c a character special file
the file's owner,the file's group owner,
b a binary special file And everybody else.
1 File's number of hard links. See the sections "Symbolic Links" and "Hard
Links"
Lynx The username of the file's owner.
Lynx The name of the group that owns the file
49 The size of the file in bytes
Jan 29 11:04 Date and time of the file's last modification
File.txt The file name
chmod command
chmod : (Change File Mode) only the file’s owner or the superuser can change the mode of a file or directory.
$ chmod [options] <permissions> <file >
chmod supports two distinct ways of specifying mode changes :
Symbol Meaning
NOTE : u Short for ‘user’
By using three octal digits, we g Group owner
can set the file mode for the
o Others but means world
owner, group owner, and
World. a Short for “all”. It’s combination of “u”, “g”, and “o”.
$ ls -l file.txt $ ls -l file.txt
-rwx - -x -wx 1 lynx lynx 49 Jan 29 11:04 file.txt - rw- r-- -w- 1 lynx lynx 49 Jan 29 11:04 file.txt
EX 01: (remove all permissions to the file) EX 01: (add a permission to everyone)
$ chmod 000 file.txt $ chmod +x file.txt
$ ls -l file.txt $ ls -l file.txt
- - - - - - - - - - 1 lynx lynx 49 Jan 29 11:04 file.txt - r w x r - x - w x 1 lynx lynx 49 Jan 29 11:04 file.txt
EX 02: (set the read, write permission to user and others) EX 02: (revoke/grant permission specifically to the user, group or world )
$ chmod 606 file.txt $ chmod g+w file.txt
$ ls -l file.txt $ ls -l file.txt
- r w - - - - r w - 1 lynx lynx 49 Jan 29 11:04 file.txt - r w x r w x - w x 1 lynx lynx 49 Jan 29 11:04 file.txt
EX 03: (give the read, write and execute permission to the group) EX 03: (modify the permissions at the same time )
$ chmod 676 file.txt $ chmod g-rwx,o=rx file.txt
$ ls -l file.txt $ ls -l file.txt
- r w - r w e r w - 1 lynx lynx 49 Jan 29 11:04 file.txt - r w x - - - r x - 1 lynx lynx 49 Jan 29 11:04 file.txt