Saturday, October 22, 2016

Linux command tips and tricks

For beginner, it is useful to know a few handy commands which can help to ease the linux learning process.

Linux is too big but there are a few commands which are commonly used.

From the website, vbird has a tutorial or these useful command but it is in Chinese, so i rewrito and simplified it in english.

Telnet
It is same as ssh and the method of using is "telnet xxx.xxx.xxx.xxx" (x is ip address)

Shutdown
"shutdown -h now" - shutdown now
"shutdown -r now" - reboot now
"shutdown -h 20.30" - shutdown at 20.30
"shutdown -h +10" - shutdown after 10 minutes

Reboot
Restart the computer. "reboot"

Cp
Copy file
"cp file1 file2" - copy file1 and rename it to file2

& and [Ctrl] + [z]
These two methods let the task running in background. Useful when you are processing exceptional long file.
Example of using: "make all &" or "make all + [Ctrl] + [z]" - it will run in background.

Fg
Show current running task. "fg"

Ps -aux
Show every task and pid. "ps -aux"

Kill
After we get a task's pid, use kill to terminate the task. "kill xxxx" (x is pid number)

Cd
Change the working directory.
"cd" - back to home
"cd ~" - back to home
"cd .." - up one level directory
"cd /usr/bin" - change the working directory to /usr/bin

Pwd
Show your current working directory. "pwd"

Ls
List out all the files
"ls -l" - list out all the details of files
"ls -a" - list out all files including hidden files.
"ls -al"  list out all files detail including hidden files.

Cat
Show the status of register or content of a file. "cat /sys/bus/usb/devices/1-2/power/control" or "cat abc.txt"

Mkdir
Create a folder. "mkdir abc"

Rm
Delete a file or directory
"rm abc.txt" - delete the abc.txt
"rm -rf abc" - delete the file abc and all contents inside abc

Mv
Move a file to different directory or change the name.
"mv abc.txt ~/" -  move the abc.txt to home
"mv abc.txt efg.txt" - change the name of abc.txt to efg.txt

Find
Useful to find a file. "find /path/name/ -name file_name"

Whereis
From the bash command history, search the particular file. "whereis file_name"

Chmod
Change the nature of a file. "r - 4, w - 2, x - 1". Needed when you want write scripts.
"chmod 755 scripts_name"

Df
List out all memory detail. "df"

Du
List out all file size. "du"

NOT YET FINISHED, WILL ADD IT WHEN I HAVE TIME. MAYBE WILL POLISH IT A BIT

No comments:

Post a Comment