Jump to content

20 Unix Command Line Tricks – Part I


securitybreach

Recommended Posts

securitybreach

Let us start new year with these Unix command line tricks to increase productivity at the Terminal. I have found them over the years and I'm now going to share with you.

 

unix-command-line-tricks.001.jpg

Deleting a HUGE file

 

I had a huge log file 200GB I need to delete on a production web server. My rm and ls command was crashed and I was afraid that the system to a crawl with huge disk I/O load. To remove a HUGE file, enter:

> /path/to/file.log

# or use the following syntax

: > /path/to/file.log

 

# finally delete it

rm /path/to/file.log

 

Want to cache console output?

 

Try the script command line utility to create a typescript of everything printed on your terminal.

script my.terminal.sessio

 

Type commands:

ls

date

sudo service foo stop

 

To exit (to end script session) type exit or logout or press control-D

exit

 

To view type:

more my.terminal.session

less my.terminal.session

cat my.terminal.session

 

Restoring deleted /tmp folder

 

As my journey continues with Linux and Unix shell, I made a few mistakes. I accidentally deleted /tmp folder. To restore it all you have to do is:

mkdir /tmpchmod 1777 /tmpchown root:root /tmpls -ld /tmp

 

Locking a directory

For privacy of my data I wanted to lock down /downloads on my file server. So I ran:

chmod 0000 /downloads

 

The root user can still has access and ls and cd commands will not work. To go back:

chmod 0755 /downloads

 

Password protecting file in vim text editor

 

Afraid that root user or someone may snoop into your personal text files? Try password protection to a file in vim, type:

vim +X filename

............

 

 

http://www.cyberciti...-tricks-part-i/

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...