# Linux command set ## Common command | Command | Note | |:--- |:---| | pwd | Show directory now | | ls | List all files ind a directory | | touch [file name] | create a file, named “file name” | | man [command text] | Get help text for command | | cp [file1 dir] [object dir] | Copy file to object directory | | mv [file1] [object dir] | Move file to object directory also used for rename. | | locate [file name] | Search file’s directory | | cat [file name] | Show the content on Terminal | | shutdown now | Shutdown system now | | reboot | Restart system | | clear | Clear screen of Terminal | | vim /etc/environment | Edit environment variables | | source /etc/environment | Update environment variables | | df -h . | know the free space in the filesystem containing the directory | | du -sh [ ./* \| dirname ] | check the total disk space used by a particular directory | | su – “user name” | Change user| | ln -s [ target file] [file] | Create symbol link for [file] to [target file] | | find -name [search string] | Find file, e.x. find -name test*.c | | uname -a | print system information, like kernel version | | microcom -s [baud rate] [device] | R/W busybox com port, e.x. microcom -s 115200 /dev/ttyGS0 | ## Console and GUI mode | Command | Note | |:--- |:---| | apt-get install ubuntu-desktop | Install ubuntu desktop | | Startx or init 5 | Swtich to ubuntu desktop | | systemctl get-default | Check default mode | | systemctl set-default multi-user.target | Set default mode to console | | systemctl set-default graphical.target | Set default mode to desktop | | Ctrl + Alt + F1 | Switch to Console mode | | Alt + F7 | Switch to GUI mode | ## GCC | Command | Note | |:--- |:---| | gcc -c | compile source files to object files without linking | | gcc -s | Produce only the assembly code | |gcc -E | Produce only the preprocessor output | | gcc -o [output file name] | write build output to output file | | gcc -I | add include directory of header files | | gcc -L | link with library file | | gcc -wall | enable all warning messages | | gcc -g | generate debug information to be used by GDB | ##SH | Command | Note | |:--- |:---| | sh [File name] | Execute sh file | ## VIM | Command | Note | |:--- |:---| | Vim [File name] | Open file in vim | | Press “i, I, o, O, a, A, r, R” | Switch to edit mode | | Press “ESC” | Switch to normal mode | | Press “:$” or [Shift]+G | Go to end of file | | :wq | Write and quit | | :w | Write | |:q | Quit | |Press Ctrl+V | block visual | |Press Y | Stop block visual and copy | |Press P | Paste copy text | |:/"search string" | Search string in text | |Press N | Repeat search last string | |set nu | Enable number of line | |set nonu | Disable number of line | |syntax on | Enable different colors as program | |syntax off | Disable different colors as program | |:u | Undo, recover last edit | |Press “.” | Redo last edit | ## Grep | Command | Note | |:--- |:---| |grep [search string] [File name] | Show the result of search string | |ls /etc/ | grep network | List file name which have “network” in /ect/ | |grep -i [search string] | Not case sensitive | |grep -n [search string] | Show line number | |grep -v [search string] | Search inverse result | |grep -r [search string] | Search in Directory and its subdirectories | |Find -name [search string] \| xargs grep [search string] | Search string in find file | ## Mkdir | Command | Note | |----------------------------- |----------------------------------------------------- | | mkdir [Folder name] | Create new Folder | | mkdir -p [Folder1/Folder2] | Create multi Folder | | mkdir -m 700 [Folder name] | Set permission and create folder | ## Chmod | Command | Note | |:--- |:---| | chmod [-R] xyz [File or Folder] | Change permission to File or Folder -R : Recursive change permission in subFolder | | xyz : number of permission<br> Read / Write / Execute => <br>-rwxrwxrwx => <br>777 =><br> r=4, w=2, x=1<br> user \| group \| others | ## Tar | Command | Note | |:--- |:---| | tar cvf “tar filename” “object filename” | Create tar Archive File for .tar | | tar xvf “filename” | Untar tar Archive File for .tar | | tar xvf “filename” -C “Folder name” | Untar tar Archive File to Folder name | | gzip “filename” “object filename” | Create tar Archive File for .gz | | gunzip “filename” | Untar tar Archive File for .gz | | bzip2 -z “filename” “object filename” | Create tar Archive File for .bz2 | | bzip2 -d “filename” | Untar tar Archive File for .bz2 | | tar zcvf “filename” “object filename” | Create tar Archive File for .tar.gz or tgz | | tar zxvf “filename” | Untar tar Archive File for .tar.gz or tgz | | tar Jcvf “filename” “object filename” | Create tar Archive File for .tar.xz | | tar Jxvf “filename” | Untar tar Archive File for .tar.xz | | tar jcvf “filename” “object filename” | Create tar Archive File for .tar.bz2 | | tar jxvf “filename” | Untar tar Archive File for .tar.bz2 | | tar -C “directory name” tar command “filename” | Tar file to directory | ## SSH | Command | Note | |:--- |:---| | sudo service ssh status | Check SSH status | | ifconfig | ## Samba | Command | Note | |----------------------------- |----------------------------------------------------- | | sudo apt install samba | Install samba file system | | sudo netstat -tulnp \| grep -e '[sn]mbd' | Check port about Samba | | sudo service smbd status | Check Samba status | | vim /etc/samba/smb.conf | Edit Samba server configuration by vim | | sudo pdbedit -a -u “User Name” | Allow local users to use | | service smbd restart | Restart samba server | ## System Process | Command | Note | |:--- |:---| | [ctrl] + z | Put process to background | | jobs | List all jobs | | jobs -l | List all jobs with PID | | fg [PID] | Take job to foreground and running | | bg [PID] | Take job to background and running | | Kill -1 [PID] | Reload config for PID | | Kill -2 [PID] | Same as [ctrl] + C for PID | | Kill -9 [PID] | Force a job to be deleted immediately | | Kill -15 [PID] | Deleted job on normal way | ## Module | Command | Note | |:--- |:---| | insmod | Install new module | | lsmod | List all module | | rmmod | Remove module | | modinfo “module name” | display the information about module | ## RM | Command | Note | |:--- |:---| | rmdir “Dir name” | Remove tire directory | | rm “File name” | Remove a file | | rm -r “File name” | Remove a non-empty directory, and all of its contents | | rm -rf “Directory name” | Remove all file in directory | ## Save terminal command print to log | Command | Note | |:--- |:---| | [command] > [/filelocation/filename] | Just output to file and overwrite | | [command] >> [/filelocation/filename] | Just output to file and append | | [command] \| tee [/filelocation/filename] | Output and save | ## Patch & Diff | Command | Note | |:--- |:---| | patch < “Patch filename” | Patch from filename | patch -d “object dir” -p1 < “patch file dir” | Patch all file in object director from patch | patch -r “patch file or other command” | Reverse a patch that is already applied | patch -b “patch file or other command” | Take a Backup before Applying the Patch | -p1 /tmp/patch mean tmp/patch | -p2 /tmp/patch mean patch| | diff -Naur “old file,dir” “new file,dir” > “patch.patch” | Generate patch file form old to new <br>Naur mean : <br>N : Treat absent files as empty <br>a : Treat all files as text <br>u : Set the default 3 lines of unified context <br>r : Recursively compare any subdirectories found | ## Git | Command | Note | |:--- |:---| | git clone “url” | Clone a repository into a new directory | | git log | Show commit logs | ## Busybox TFTP | Command | Note | |----------------------------- |----------------------------------------------------- | | tftp -g -r [FILENAME] [SERVERIP] | Get file form server.<br>-l [FILE] Local FILE. → change file name<br>-r [FILE] Remote FILE. → keep file name<br>-g Get file from server.| ## IP | Command | Note | |:--- |:---| | ip a | Show ip configuration, like ipconfig | | ip link add link enp0s9 name enp0s9.101 type vlan id 101 | Create vlan on interface ‘enp0s9’, vlan id 101. | | ip link set dev enp0s9.101 up | | | ifconfig eht0 192.168.0.20 | Set ip for interface ‘eht0’. | | cat /proc/net/vlan/ | Check vlan id, status | ## Serial | Command | Note | |:--- |:---| | dmesg | grep -i tty | Check tty device | | cat /proc/tty/drivers | Check tty drivers | ## Devices | Command | Note | |:--- |:---| | cat /proc/devices | Finding out about drivers at runtime | | cat /sys/class/[devices] | Get all active devices | | cat /sys/kernel/debug/gpio | List gpio | ## Systemctl early boot service that configures sysctl kernel parameters | Command | Note | |:--- |:---| | systemctl start [service] | Start target sevice | | systemctl stop [service] | Stop target sevice | | systemctl status [service] | Get status of target sevice | | systemctl restart [service] | Restart target sevice | ## start-stop-daemon | Command | Note | |:--- |:---| | start-stop-daemon [-S \| --start ] [-b] [-x] [daemon programs name] | Start a daemon programs in background | | start-stop-daemon [-S \| --start ] [-b] [-x] [daemon programs name] [-n] [process-name] | Start a daemon programs in background and show as [process-name] | | start-stop-daemon [-S \| --start ] [-b] [-x] [daemon programs name] [-n] [process-name] [-a] [path name] | Start a daemon programs in background and show as [process-name], start the process specified by pathname | | start-stop-daemon [-K \| --stop ] [-x] [daemon programs name] | Stop a daemon programs in background |