Master Command Lines

After I switched to Ubuntu on my home computer, I really enjoy the convenience of Unix system. Besides Steam began to release games to Linux system. I probably will not change back to Windows. Here is a list of some useful unix command lines. Most of them are from Master Comand Lines from Lifehacker, but I reorganize it and add some other examples. This could be a good starting point of learning Unix command lines.

File Managment

>>ls [options]

List Files, -l for a detailed listing, -t will sort the results by file time, -s will sort by file size; and -r will reverse the sorting; –a for hidden files;

>>cd ..     /*Return to the higher directory*/
>>cd –     /*Quickly switch back to the previous working directory */
>>cd folder/subfolder     /*Go to the subfolder directly*/

>>mkdir [foldername]

Create one or more Folders

>>rmdir [foldername]

Remove Folders

>>touch [filename]

Create a new, blank file

>>rm [filename]
>>rm *
>>rm [options] [filename]
Removing Files. -r option for recursive, and the -f option for force, for example >>rm -f -r

>>nano [path]
Edit Plain Text Files under certain directory.

>>more [filename]
Displaying Files.

Run Scripts 

./scriptname.sh

Running a Script in the Current Folder

System Control

>>ps aux     /*to see a list of system processes */
>>kill <pid>    /*to kill any processes you want to, pid is the process number*/
>>top    /* list all process in order and then you can type K to kill any process you want*/
>>history   /*List command history*/

Remark: top is very useful.

Shortcut

>>sudo !!    /*Repeat previous command*/
>>!cat    /*run the last command that used cat*/
>>ifconfig    /*It shows you the IP address of your computer, the MAC address of your Ethernet and Wi-Fi cards, and a ton more.*/

Ctrl + U: Clears the line from the cursor point back to the beginning.
Ctrl + A: Moves the cursor to the beginning of the line.
Ctrl + E: Moves the cursor to the end of the line.
Ctrl + R: Allows you to search through the previous commands.
Ctrl+K: This deletes the line from the position of the cursor to the end of the line.
Ctrl+W: This deletes the word before the cursor only.
Tab: For auto finish
Dragging Files Into the Terminal Window: For Path

Some Useful Alias

>>alias ls=’ls –l’
>>alias la=’ls -a’

>>alias agi=’sudo apt-get install’    /*you could simply type agi packagename at the shell to install any package in fewer keystrokes.*/
>>alias update=’sudo apt-get update’alias ll=’ls -l’
>>alias emenu=’aterm nano -e ~/.e16/menus/user_apps’       /*an alias that opens up a file for editing*/

>>alias desk=’cd ~/Desktop’

Cool Tricks: Some Combinations

>>ls –l | more
>>ls -l > filename.list     /*write results >>ls -l to filename.list*/
>>cat filename.list | grep [keyword] > filefound.list    /*write filename.list lines with keywords into [filefound.list]*/
“|” for adding more commands in one line.
“cat” command to display the contents of that file
“>” for piping that into the grep command (detailed further below), and then redirect that output into a separate file
“grep” command (detailed further below), and then redirect that output into a separate file

>>history | grep nano     /*see all the recent commands you ran that included [nano]*/
>>for f in *.txt;do echo $f;done   /*Loop through all the .txt files in the current directory and display them*/
>>find . –name “*.txt” –mtime 5    /*Find all files with .txt in the name that were modified in the last 5 days*/
>>rename –v ‘s/foo/bar/g’ *   /*Rename filenames in batch: rename all files containing foo to contain bar instead*/
>>grep –ir “text string” *    /*Search through all files in the current directory and below it (including subdirectories) for “text string”. Quickly find text within files, even searching through subdirectories.*/

Resources and Reference

Using Bash Shortcut Keys
Customizing Your Command Shell
Using Aliases
Find Files
Top 10 Tools That Are Better in the Command Line

Tagged on: ,

Hey, what do you think?