Ad Code

Ticker

6/windows/ticker-posts
Up to 47% OFF on eufy Appliances Christmas Sale

15 Linux Commands and shortcuts that will change the way you use Linux System

 

15 Linux Commands that will change the way you use Linux System

If you use any Linux OS distribution, you probably already realize that linux commands are the fastest way to do certain things. In this article, I would share the Linux commands that I use very often and I find them quiet useful. 

Linux command

Go back to my previous working directory

cd -

Pushd (save a directory) and popd (go back to that saved directory) 

push the current working directory to the stack
pushd .   
push the /etc directory to the stack  
pushd /etc   
Next, do some work in any directory, then type popd to return to the directory that is on top of the stack (the last directory to you pushed)
popd or cd popd


Clear the terminal 

Move the cursor to the top of the terminal
Ctrl + L
Clear the terminal  history. This  clear directory stack by deleting all entry
history -c  
  
Clear a specific line of the history, in this case, line 4 of the history is deleted. This is useful if you have certain important information like password that you don't want to have in the history log. 
history -d 4 

Send an application or a process to the background

Freeze a running application: 
Ctrl + Z    
then, sent it to background by typing:  bg 
Next, you can do something else; when you are done, send the background application back to the foreground by typing:   fg

Use case: After "ctrl + Z", the process is frozen, and you can type “bg” to make it continue running in the background. I use this all the time, for instance. When I start NodeJS service interactively. Then, I press "ctrl + Z" , "bg", to run it in background and see the log.

Note: if you close the cli , you will lose whatever is running in the background

Re-run the most recent command 

This can be useful when you forget to type sudo at the beginning of the command, instead of retyping it, just type "sudo !!" and it will rerun the last comment with sudo. Example: 
apt update
sudo !!    ( This will will run: sudo apt update)


Display command's history

This all the commands that you have been typing
history
run the 4th  command in the history, it is read: bang 4
!4    

Bonus:
To make the history command show the date, when that command was executed, edit the  ~/.bashrc to include the following:
HISTTIMEFORMAT="%Y-%m-%d %T "

Increase the font/reduce size (works on Ubuntu)

Increase the font size: Ctrl + Shift + "+"
Reduce the font size: Ctrl +  "-"
You can also set the font on Putty and Xterm using: 
Ctrl + Right Click 

Quickly delete everything on the line

Ctrl + U

Move the cursor Around the command

Move the cursor at the beginning of the line. This can also be handy when you forget to type sudo at the beginning of a long command. 

Ctrl + A  
Move the curse to the front of the line:  
Ctrl + E
This is actually one of my favorite shortcut, since it is much faster than using the arrow keys. 

 

Chain 2 commands on the same line with semi colon or &&

ls -l; echo "echo" 
ls -l  && echo "echo"
What is the different between these 2 commands?
Note that with &&, it like an AND, both commands have to run successfully. If the first command is unable to run, then the second command will not run. 
With the semi column ";", the commands are independent; meaning, even if one fail,  the other one will still run.
 

Empty the content of a file without deleting or opening it

This will set the size of hello.txt file to 0, so the file will be empty
truncate -s 0 hello.txt

Display the output of a command in table format

The mount command display all the disk on the system. by piping it to column -t, it will display in table format, making it easy to read.
mount | column -t

Tail and Head command

Tail and Head command's are very similar.  Head or tail commands are simple ways to display the beginning or end of text files. Both display the first 10 lines by default.
syntax:
tail /path/to/logFileOrAnyfile

show the last 10 line by default:

tail -n 10 /var/log/auth.log
Note: /var/log/auth.log is a good log file to keep an eye on; it is where login logs goes in debian systems. 

Sometime, you want to see changes on the file as it is being updated, you can use the follow option "-f". 
tail -f /var/log/auth.log

Head command, return the first characters

head –c8 <filename> 
return the first 8 characters of a line: 


We hope you have learned something new in this post. If you have other Linux command's that you use often and think they are very useful, please share them in the comment below.

 Are you also a Windows user? Here are my to Top 18 Windows shortcuts.

Don't forget to share this other Linux users.

Post a Comment

0 Comments

Great domain = More Business

Popular Domains for just 99 Cents at Namecheap!