Basic command Flashcards

1
Q

CTRL+D == exit

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

man ‘command’

A

command manual
@6 jeld darad
** bazi dastoorat dar chand jeld hastand
man 5 passwd => mige az jeld 5 baraam bekhon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

env

A

print envirenment variable

USER = The name of the logged-in user

PATH = List of directories to search for commands, colon separated

EDITOR = Default editor

HISTFILE = Where bash should save its history (normally .bash_history)

HOSTNAME = System hostname

PS1 = The Prompt! Play with it

UID = The numeric user id of the logged-in user

HOME = The user’s home directory

PWD = The current working directory

SHELL = The name of the shell

$ = The process id (or PID of the running bash shell (or other) process

PPID = The process id of the process that started this process (that is, the id of the parent process)

? = The exit code of the last command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

if we want to print or use this character without interpretation we have to ?
* ?[]’”$;&()|^<>

A

quote them or use with \

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

echo -e “hello\nhello\thello\v”

A

@-e chizi ke baad az \ miaad ro tafsir mikone

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

mhdadizadeh=’mohamad\ hadi\ dadizadeh’
echo $mhdadizadeh

A

define envirenment var and print by echo
**space to bayad ba \ scape kard
**dastoor aval bayad bedoon fasele bashe
**var moghe echo baayad $ dashte baashe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

export mhdadizadeh=hadi

A

@dar hame level ha taarif mishe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what happen when enter a command?

A

first : check if is a builtin command then execute
second : @file ha ee ka dar $PATH adderess dadim be tartib check mikone va age onja ham chizi peyda nakard error mide

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PATH=$PATH:/home/mhdadizadeh/bin

A

add path to $PATH

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

@linux current dir ro ham baraye ejraye barname ha check mikone? why?

A

@na , be dalayel amniati

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

which ‘command’

A

@age in command ro bezanam chi run mishe?

The which command searches through the directories that are defined in the $PATH environment variable for a given filename.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

unset env_var

A

unset envirenment variable

-v : unset shell var if exist
-f : unset shell func if exist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

$HISTFILE Vs history

A

$HISTFILE : baad az exit command ha tooch save mishan
history : yek shell builtin command ast va dastorat haman moghe zakhire mishavan

Ctrl+R = Backward Search
Ctrl+O = Run the command you found with Ctrl+R
!! = Run the last command
!10 = Run command number 10 of history
!text = search backward for text, and run the first found command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

whereis ‘command’

A

@khodesh va mokhallafatesh koja hastan
**baazi dastoorat chand ja hastan ya maani haye motafaveti daaran

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

whatis ‘command’

A

print first line of discription

** age chand ta tafsir dasht hamasho mide

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

type ‘command’

A

@yek command ro midi behesh va mige chetor tafsir mishe

**mamolan path file ejraee ro mide

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

cd /home/mhdadizadeh

A

Absolute Paths
** / means root dir

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

cd dir1/dir2/dir3

A

Relative Paths

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

cd
cd ~
cd $HOME

A

home dir

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

cd ~[username]

A

goes to another user’s home directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

cd ..

A

moves one directory up.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

cd -

A

moves to your previous directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

uname -a

A

Gives you data about the system

-s = Print the kernel name. This is the default if no option is specified.
-n = Print the nodename or hostname.
-r = Print the release of the kernel.
-m = Print the machine’s hardware (CPU) name.
-o = Print the operating system name.
-a = hameche ba ham

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

ls -R

A

lists all the files in the subdirectories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
ls -a
shows hidden files in addition to the visible ones
26
ls -lh
shows the file sizes in easily readable formats, such as MB, GB, and TB
27
ls -ltrh
l : long detail t : sort by time r : reverse sort h : human readable ** -S : sort by time
28
cp file dir
copy file to dir
29
cp file1 file2
copy file to another file @age nabood misaze @age bood, overwrite
30
cp file1 file2 file3 dir
@chand ta file ro beriz to ye dir
31
cp -R dir1 dir2
@copye ye dir va cole mohtaviatesh to ye dir dige
32
cp -b file1 file2
-b : (--backup) will make backups of overwritten files
33
cp -p file1 file2
-p : will preserve the attributes. ** moshakhasat file aval ro ham nigiri
34
cat file1 file2 file3
@file haye voroodi ro migire concat mikone va namayesh mide ** cat -n file1 : shomare khat mizane
35
bzcat, xzcat, zcat, gzcat
These let you see the contents of compressed files without uncompressing them first
36
cat file1 file2 > dir/file3
@chand ta file ro yeki kon beriz to ye filee dige
37
less file or cat file | less
q = Exit /foo = Searches for foo n = Next (search) N = Previous (search) ?foo = Search backward for foo G = Go to end nG = Go to line n PageUp, PageDown, UpArrow, DownArrow = You guess!
38
od file
(Shows files in formats other than text). Normal behavior is OctalDump (showing in base 8) -t will tell what format to print: -t a for showing only named characters -t c for showing escaped chars. You can summarize the two above to -a and -c
39
mv file1 file_name
rename file to another name
40
mv file1 dir
move file to another place
41
mv Vs cp
@mv file ro as maghsad pak mikone @cp file ro as maghsad pak nemikone @har do dar har sorat ya file ro misazan ya overwrite mikonan
42
mkdir dir_name
@saakht dir
43
mkdir dir/dir/dir_name
@saakhte dir dar yek dir dige **parent dir bayad mojood bashe
44
mkdir -p dir1/dir2/dir3
@saakhte hamzaman dir va parent hash
45
mkdir -m777 dir/dir/dir_name
@saakhte file hamraah bo dadan permissio
46
mkdir -v file1
prints a message for each created directory
47
switch: -v
@harf bezan begoo dare chi mishe
48
switch: -r
@baazgashti amal kon
49
rmdir dir
delete empty dir
50
rmdir -p dir1/dir2/dir3
@khodesh va hame ajdadesho paak kon ** agar khaali boodan
51
rm file1 file2 file3
remove files
52
rm -i
@ghabl as pak kardan soal dkon
53
rm -f
@bedoon soal har chi didi pak kon
54
rm -r
@be soorat baazgashti boro toye pooshe ha va hame file ha ro pak kon
55
touch file1
create new file or change time of creation of exist file
56
touch -t [timestamp] file1
specify time of file by timestamp
57
touch -d [unix_time] file1
specify time of file with unix base time
58
$ touch -t 200908121510.59 file1 $ touch -d 11am file2 $ touch -d "last fortnight" file3 $ touch -d "yesterday 6am" file4 $ touch -d "2 days ago 12:00" file5 $ touch -d "tomorrow 02:00" file6 $ touch -d "5 Nov" file3
specify creation time of file
59
touch -r refrens_file file1
specify file creation file by referencing to another file
60
split -n 2 file1
split file into pieces -n = split file by number of pieces -l = split file by number of line -b = split file by number of bytes -d = use numeric suffix start from 0
61
cut -f1 -d, file1
cut one or more columns from a file -f = selected columns 1,3,4 or range 1-3 -d = delimiter (only one character) ** default delimiter is TAB
62
nl == cat -n
63
sort file1
-r : reverse sort -n : sort numerically -d : ignore blankes
64
uniq file1
** the input most be sorted file -c = count of each item -u = show only non-repeated item -d = show only repeated item
65
find ./ -type f _______ -type d -type l
@to in directory hame file ha ya dir ha ya link ha ro peyda k
66
find ./ -iname "file_name"
@to in dir har chi ba in name hast to bedo **iname case sensitive nist
67
find . -iname '*.png' -type f -size -100k
finish with .png with type file with size less than 100k
68
find . -type f -mmin -30
mmin : Modified Minutes cmin : Status Change Min amin :‌ Access Minutes ** -ls az file ha ls migire -delete file ya dir haye peyda shode ro pak mikone
69
find ~ -type f -mmin -1 -exec wc -l '{}' \;
@-exec aakhar find miad va ye command roye natayej ejra mikone
70
grep
for search by regex in file or stdin
71
grep 'text' file1
search text in file
72
16. du command
73
head file1
print first 10 lines of file -n :‌ count of line you want to display -c : count of byte you want to display -q or –quiet : will not print headers specifying the file name.
74
head -n 5 file1
print first 5 line of file
75
tail file1
print last 10 line of file -n :‌ count of line you want to display -c : count of byte you want to display -q or –quiet : will not print headers specifying the file name.
76
tail -n 5 file1
print last 5 line of file
77
tail -f file1
follow end of the file and if new data added then display
78
cat file | tr '123' '۱۲۳' or echo 123 | tr '123' 'abc'
@ mitoone yek majmooee character ro ba ye mahmooee dige jaa be jaa kone ** pure filter ast va input nmigirad
79
sed s/hadi/mohamad/g file
sed is stream editor Sed is a great tool for replacing text with using regular expressions replace hadi with mohamad all over the file
80
wc file1
word count -l = line -w = word -c = bytes
81
wc -l file | cat file - file echo "bar" |cat file - file
the output of previos step replace with -
82
tell me three hashing function ?
@yek input ba size delkhah migire yek outup uniqe ba size yeksan mide md5sum sha256sum sha512sum ** mishe chand ta file dad va hash hamashono zire ham did
83
Wildcards:‌ *
means any string
84
Wildcards:‌ ?
means any single character
85
Wildcards:‌ [ABC]
matches A, B, or C
86
Wildcards:‌ [a-k]
matches a, b, c, ..., k (both lower-case and upper-case)
87
Wildcards:‌ [0-9a-z]
matches all digits and numbers
88
Wildcards:‌ [!x]
means NOT X
89
19. diff command
90
gzip file1 gunzip file1
91
bzip2 file1 bunzip2 file1
92
xz file1 unxz file1
93
xz file1 -k
-k = keep the original file when create compress file
94
zip [file_name.zip] file1 file2 ... unzip file.zip
95
tar -cvf file.tar [file or dir] [file or dir] [file or dir]
@archive kardan file ha dar file.tar -c : create -f : file -v : verbus
96
tar xf file.tar--directory ~/dir
extract tar file to differant dir -x : extract -f : file
97
tar -xf file.tar
extract tar file -x : extract -f : file
98
tar xfz 2file.tar.gz
** first decompres from zip then extract from tar
99
tar tf file.tar
-f : file name -t : lists the content of a file
100
tar uf file.tar file3
-u :‌ archives and adds to an existing archive file.
101
tar
x : Extract files f : Tar archive name --directory : Set directory name to extract files -C : Set dir name to extract files -z : Work on .tar.gz (gzip) file format -j : Work on .tar.bz2 (bzip2) file format -J (capital J) : Work on .tar.xz (xz) file format -v : Verbose output i.e. show progress on screen
102
21. chmod command
103
22. chown command
104
touch -r [refrens file] file1
specify file creation file by refensing to another file
105
file file_name
@formate file ro mide
106
file -i filename
@mime type ro mide
107
dd if=file1 of=file2 count=2 bs=4096
@block size ro migire va be tedad count as file1 mirize too file2
108
dd if=file | gzip > file.dd.gzip
copy and zip the file
109
@linux current dir ro ham baraye ejraye barname ha check mikone? why?
@na , be dalayel amniati
110
tell me number of the term bellow: stdin? stdout? stderr?
stdin : 0 stdout : 1 stderr : 2
111
ls > file
Redirect STDOUT to a file; Overwrite if exists
112
tree >> file
Redirect STDOUT to a file; Append if exists
113
ls undefine.txt file.txt >>stdout.txt 2>>stderr.txt
@it's clear?
114
command 2> file
Redirect STDERR to a file; Overwrite if exists
115
command 2>> file
Redirect STDERR to a file; Append if exists
116
command &> file
Redirect both STDOUT and STDERR; Overwrite if exists
117
command &>> file
Redirect both STDOUT and STDERR; Append if exists
118
tr '۱۲۳' '123' < file.txt
@file hadi be onvan stdin be tr dade mishe
119
command >log.txt 2>&1
@stderr ro ham beriz hamon ja ke stdout ro rikhti &0 :‌ hamon ja ke stdin &1 : hamon ja ke stdout &2 : hamon ja ke stderr
120
ls 2>&1 >file1
@ stderr ro beriz hamon ja ke stdout ro mirizi , hala std out ro beriz to file1 , yanii hamashon to file1
121
ls j* x* >file1 2>/dev/null
stdout to file1 stderr ro beriz door ** /dev/null == aashghali
122
cat << END > file
create and write file at the same time
123
command1 | command2
stdout of command1 == stdin of command2
124
question? bishtarin distribution linux be tartib tedad (ba pipe)
125
echo hadi | xargs -I variable cat variable
@roo khorooji dastor ghabl ye command run mikone ** -I : variable misaze
126
echo text | tee -a file
append text to file also write in stdout **without -a , text will be overwriten
127
[process or program] &
start and send the process to background
128
when process is running: Ctrl+c ? Ctrl+z ?
Ctrl + c : break Ctrl + z : suspend
129
jobs
list all the jobs -l : lists process IDs along with their information. -n : lists jobs whose statuses have changed since the last notification. -p : lists process IDs only.
130
bg %[process_number]
send a process to background
131
fg %[process_number]
send the process to foreground
132
jobs -l
list all the jobs + process id
133
nohup ping google.com
The nohup command lets you run your commands even after you close the terminal or logout. By default it writes its output to nohup.out
134
ping google.com &>~/logs &
send output and error to logs and send process to background
135
ping [option] [hostname_or_IP_address]
send ICMP ECHO_REQUEST to network hosts
136
kill -SIGNAL_ID_OR_NAME process_id
signal id and name: 1 = HUP = Informing the process that its controlling terminal (like an ssh connection) is terminated 15 = TERM = normal termination request 9 = KILL = forcefully kills the process SIGTERM requests a program to stop running and gives it some time to save all of its progress. The system will use this by default if you don’t specify the signal when entering the kill command. SIGKILL forces programs to stop, and you will lose unsaved progress. Remember the nohup command ? :) It means " do not respond to the hup signal ".
137
killall process_name
This command Will send the given signal (or by default 15) to all processes with the given name
138
pkill *ping
Will send the given signal (or 15) to all the processes with a specific pattern in their name
139
ps -ef
show all the process on a system -e == -A : all process -f == full format
140
ps -u
show all the process on the system -a = -e = all -u = user
141
ps -aux Vs ps -ef
142
??? => ps -af --sort +comm,-sid
sort process by key
143
pgrep 'text'
pgrep 'text' == ps -ef| grep 'text'
144
top
-display Linux processes simple monitoring of the system You can see the processes, system load, uptime, CPU status, memory, ... and do some stuff. The top command can also help you identify and terminate a process that may use too many system resources. h = help q = quit M = sort based on memory usage" c = show full commands k = kill after asking pid and signal
145
free
The free command will show you info about the system memory -m = for megabytes -g = for gigabytes or even -b = for bytes -h = for human readable
146
uptime
command shows the time, systems uptime (how long the system has been running), how many users are logged in, and the load average of 1, 5 & 15 minutes Although it's one of the most important KPIs of the system status, some of the experienced Linux admins do not know what the load average means. The load average shows how many processes are in the to be run queue. If this number is higher than the number of your CPU cores, you are in a bad situation. If it's close to the number of your cores constantly, it's kind of dangerous, and if it's less than 1/10th of your core numbers, your system is kind of idle. Do you remember how to check the number of your cores? Its in /proc/cpuinfo or nproc.
147
watch 'command'
It lets you run and check the output of a command in specific time intervals (default is 2 seconds). -n =To specify the interval in seconds -b = Beep if the command has a non-zero exit -d = Shows the difference between runs
148
sudo 'command'
lets you perform tasks that require administrative or root permissions.
149
tac file1
displays content in reverse order
150
locate file_name
locate is a Unix utility which serves to find files on filesystems. It searches through a prebuilt local database of all files on the filesystem generated by the updatedb command. Note it is essential to update the database as recent files saved over a period of fewer than 24 hours are not updated into the database by default and the database is updated once within 24 hours span. ** age donbal file ha ee hasti ke kamter az 24 saat ghabl dorost shoden. 'updatedb' bezan
151
df -h
report file system space usage -h : human readable
152
du -sh dir
estimate file space usage -s : totla -h :‌human readable (GB) -m :‌ size in MB -l : size in KB
153
diff -c file1 file2
compare files line by line -c : displays the difference between two files in a context form. -u :‌ displays the output without redundant information. -i : makes the diff command case insensitive.
154
tar tf file.tar
-f : file name -t : lists the content of a file
155
ls -l file1: -rw-r--r--. 1 mhdadizadeh mhdadizadeh 0 Jan 4 16:00 file1
1 ( - / d ) : file or dir 2 ( rwx ) : owner's permissions 3 ( rwx ) : group's permissions 4 ( rwx ) : others' permissions 1 : the number of hard links. A hard link is an additional name for an existing file mhdadizadeh mhdadizadeh : the owner and group owner of the file. 0 : the size of the file in bytes Jan 4 16:00 : the last modification date file1 : the name of the file/folder
156
tell me number of each permition : r (read) : w (write) : x (execute) : tell me permition of this number: 3 : 5 : 6 : 7 :
r (read) : 4 w (write) : 2 x (execute) : 1 3 : execute - write 5 : read - execute 6 : read - write 7 : read - write - execute ** owner - group - other ** If you don’t want to give any permission to a user, enter 0 into the corresponding spot.
157
chmod 777 [file or dir]
@dadan hame permissions ha be hame user ha
158
chown user_1 file1
The chown command lets you change the ownership of a file, directory, or symbolic link to a specified username. **chown [option] owner[:group] file(s) ? : har file yek owner va yek group darad? ? : mishe owner va group kamelan az ham part bashan?
159
&&&‌ cut -d: -f1 /etc/passwd
username of the system user
160
&&& wget [option] [url]
The non-interactive network downloader
161
hostname == uname -n
Run the hostname command to know the system’s hostname
162
&&& useradd
create a new user or update default new user information
163
alias rm=’echo "boro in daam bar morghi degar neh"’ unalias [rm]
alias allows you to create a shortcut with the same functionality as a command
164
&&& su [options] [username [argument]]
The switch user or su command allows you to run a program as a different user -p or –preserve-environment keeps the same shell environment, consisting HOME, SHELL, USER, and LOGNAME. -s or –shell lets you specify a different shell environment to run. -l or –login runs a login script to switch to a different username. Executing it requires you to enter the user’s password.
165
ps -------------- ps -u mhdadizadeh
@ye snapshot as process haye feeli mide process ID (PID) type of terminal (TTY) running time (TIME) command that launches the process (CMD) switches: -T : displays all processes associated with the current shell session. -u username : lists processes associated with a specific user. -A or -e shows all the running processes.