Linux Flashcards
Remember command
How to check g++ version in system?
dpkg –list | grep compiler
how to update the Ubuntu package list?
sudo apt-get update
How to find location of command?
whereis For example: whereis g++
How to show current path?
pwd
how to completely disabling Touchpad
xinput list xinput set-prop 12 “Device Enabled” 0 Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Logitech USB-PS/2 Optical Mouse id=13 [slave pointer (2)] ⎜ ↳ ImExPS/2 Generic Explorer Mouse id=12 [slave pointer (2)]
What command to show ID, group etc
id
$ ls -l show file attributes, what does the first symbol mean?
- Regular file d Directory l Symbolic link
Read permission of directory allow to ?
Allows file names in the directory to be read
Write permission of directory allow to ?
Allow entries to be modified within the directory like add new file
Execute permission of directory allow to?
Allows access to contents and metadata for entries like the owner, modified date etc..
how to show all users in the system?
less /etc/passwd or getent passwd
How to list all users only for username?
awk -F: ‘{ print $1 }’ /etc/passwd
how to display the list of recent commands in Linux?
history
what is default separator in awk
White-space character which is space or tab
What is the option value to set separator in “awk” command?
-F For example: awk -F: ‘{print $1}’ /etc/passwd
What is $0 in awk?
that repersent the whole line
what is statement control in awk?
if else while do for continue break Example if ( expr ) statement if ( expr ) statement else statement while ( expr ) statement do statement while ( expr ) for ( opt_expr ; opt_expr ; opt_expr ) statement for ( var in array ) statement continue break
awk ‘{if($3 != 0) {a = ($3/$4); print $0, a;} else if($3==0) print $0, “-“ }’ file_name
How “statement” structure in awk?
Group of statement are blocked via {…} and can be separated by semi-colons or new line For example: awk -F: ‘{if ($3 > 100) { x=x+1; print x, $1, $3} }’ /etc/passwd
What is permission categories?
u:User, g:Group, o:Other and a:All
command ls -l, what is the first column mean?
1st char: type, file, dir or link next 3: user permission rwx next 3: group permission rwx next 3: other permission rwx
How to change permission of file?
chmod and provide u=rwx,g=rwx,o=rwx or we can use u+ or u- or we can use 777
What is the command to list file in directory that include file that start name with dot (.)?
ls -a
How to change directory to Home?
cd ~
How to find file name that start wiht utp* from current directory and under?
find . -name utp*
how to display the execute of ls -l on file that start with uta* from current directory and under?
find . -name utp* -exec ls -l {} \; We need {}, find will subsitute {} filename they found. also it need “;” (put \ escape to prevent shell to interpret it)
How to list file that size > 10 Megabite and perform ls -l
find -size +10M -exec ls -l {} \;
What command to find executable file?
find . -executable -type f
How to unzip zip file from Windows
unzip zip_file
How to grep recursively?
grep -r whatever ./
Grep to show line before & after
grep -C5 “xxx”
what is default /bin/sh in Ubuntu
dash and in RedHat is bash
What is link on linux
Hard link and Soft link
ln <source></source> <link></link> // this is hard link</source>
ln -s <source></source> <link></link> this is soft linke</source>
we can remove it by
rm <link></link>
or — unlink <link></link>
To create environment variable
export TEST=1234
to show it — echo $TEST
to remove it — unset $TEST
How to list files by newest date?
ls -lt
To display host IP address
ifconfig
To check ubuntu version
lsb_release -a
How to create short-cut command line?
alias
alias ena_serv = “systemctl list-unit-files | grep enabled”
to make it permanent, add those line in ~/.bash_aliases
How to display process in linux
ps aux
or top command
to display top 5 usage
ps aux | ort -nrk s3,3 | head -n 5
to refresh every 2 seconds
watch “ps aux | ort -nrk s3,3 | head -n 5”
How to kill process
kill -9 “id”
How to display all socket
ss -a
netstat –listen
netstat -ratn
How to check memory
free
/proc/meminfo
top
What is the max size of file name?
255
How many mode in vi?
3 modes
command mode, edit mode and replace mode
What commands to see content of file?
cat, head, tail, cat, more, less
List of most use network command
netstat -tulpn
ping, telnet, tracerout
ifconfig -a
host www.google.com
ip address show
How to check disk usage of directory?
du -sh “directory name”
show disk usage
df -ah
how to check system infomation
uname -a
How to check disk mount at boot time
check file
/etc/fstab
we pronouce “file system tab”
How to search contain of file and show 5 lines before & after
grep -C5 “Whatever”
What is systemd?
it is stand for “system-deamons”
- It work like Window Services.
- It is used with sysctrl command.
What is /bin/sh
In Unbuntu it is “dash”.
In RedHat is bash