Basic command Flashcards
CTRL+D == exit
man ‘command’
command manual
@6 jeld darad
** bazi dastoorat dar chand jeld hastand
man 5 passwd => mige az jeld 5 baraam bekhon
env
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
if we want to print or use this character without interpretation we have to ?
* ?[]’”$;&()|^<>
quote them or use with \
echo -e “hello\nhello\thello\v”
@-e chizi ke baad az \ miaad ro tafsir mikone
mhdadizadeh=’mohamad\ hadi\ dadizadeh’
echo $mhdadizadeh
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
export mhdadizadeh=hadi
@dar hame level ha taarif mishe
what happen when enter a command?
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
PATH=$PATH:/home/mhdadizadeh/bin
add path to $PATH
@linux current dir ro ham baraye ejraye barname ha check mikone? why?
@na , be dalayel amniati
which ‘command’
@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.
unset env_var
unset envirenment variable
-v : unset shell var if exist
-f : unset shell func if exist
$HISTFILE Vs history
$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
whereis ‘command’
@khodesh va mokhallafatesh koja hastan
**baazi dastoorat chand ja hastan ya maani haye motafaveti daaran
whatis ‘command’
print first line of discription
** age chand ta tafsir dasht hamasho mide
type ‘command’
@yek command ro midi behesh va mige chetor tafsir mishe
**mamolan path file ejraee ro mide
cd /home/mhdadizadeh
Absolute Paths
** / means root dir
cd dir1/dir2/dir3
Relative Paths
cd
cd ~
cd $HOME
home dir
cd ~[username]
goes to another user’s home directory.
cd ..
moves one directory up.
cd -
moves to your previous directory
uname -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
ls -R
lists all the files in the subdirectories
ls -a
shows hidden files in addition to the visible ones
ls -lh
shows the file sizes in easily readable formats, such as MB, GB, and TB
ls -ltrh
l : long detail
t : sort by time
r : reverse sort
h : human readable
** -S : sort by time
cp file dir
copy file to dir
cp file1 file2
copy file to another file
@age nabood misaze
@age bood, overwrite
cp file1 file2 file3 dir
@chand ta file ro beriz to ye dir
cp -R dir1 dir2
@copye ye dir va cole mohtaviatesh to ye dir dige
cp -b file1 file2
-b : (–backup) will make backups of overwritten files
cp -p file1 file2
-p : will preserve the attributes.
** moshakhasat file aval ro ham nigiri
cat file1 file2 file3
@file haye voroodi ro migire concat mikone va namayesh mide
** cat -n file1 : shomare khat mizane
bzcat, xzcat, zcat, gzcat
These let you see the contents of compressed files without uncompressing them first
cat file1 file2 > dir/file3
@chand ta file ro yeki kon beriz to ye filee dige
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!
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
mv file1 file_name
rename file to another name
mv file1 dir
move file to another place
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
mkdir dir_name
@saakht dir
mkdir dir/dir/dir_name
@saakhte dir dar yek dir dige
**parent dir bayad mojood bashe
mkdir -p dir1/dir2/dir3
@saakhte hamzaman dir va parent hash
mkdir -m777 dir/dir/dir_name
@saakhte file hamraah bo dadan permissio
mkdir -v file1
prints a message for each created directory
switch: -v
@harf bezan begoo dare chi mishe
switch: -r
@baazgashti amal kon
rmdir dir
delete empty dir
rmdir -p dir1/dir2/dir3
@khodesh va hame ajdadesho paak kon
** agar khaali boodan
rm file1 file2 file3
remove files
rm -i
@ghabl as pak kardan soal dkon
rm -f
@bedoon soal har chi didi pak kon
rm -r
@be soorat baazgashti boro toye pooshe ha va hame file ha ro pak kon
touch file1
create new file or change time of creation of exist file
touch -t [timestamp] file1
specify time of file by timestamp
touch -d [unix_time] file1
specify time of file with unix base time
$ 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
touch -r refrens_file file1
specify file creation file by referencing to another file
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
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
nl == cat -n
sort file1
-r : reverse sort
-n : sort numerically
-d : ignore blankes
uniq file1
** the input most be sorted file
-c = count of each item
-u = show only non-repeated item
-d = show only repeated item
find ./ -type f
_______
-type d
-type l
@to in directory hame file ha ya dir ha ya link ha ro peyda k
find ./ -iname “file_name”
@to in dir har chi ba in name hast to bedo
**iname case sensitive nist