Page 1 of 1

Intermediate Linux commands for developers Rate Topic: ***** 1 Votes

#1 wordswords  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 272
  • Joined: 17-December 11

Posted 26 December 2011 - 06:32 PM

*
POPULAR

Here are some techniques which I use regularly:

find -name "*.svn" -exec rm {} \;


Delete all files and directories matching a certain wildcard, here I use "*.svn", from the current directory and below. This particular command will also remove your svn working directory and turn it into a directory free of .svn files, similar to what the directory would be if you use 'svn export'.

ls -lhart


ls 'long style' with human readable file sizes, showing all files, sorted by last modified date to show the most recently modified file at the bottom of the list. Try it.

. ~/.bash_profile


This simple dot before the shell script will execute the following file in the context of the current shell, so all variables will be saved in this shell instance.

> /tmp/blank


Create an empty file at /tmp/blank . It is identical to touch /tmp/blank but is an easier to remember mnemonic.

history


Show previous commands numbered from first to last

history | grep ssh


Show all instances of you connecting through ssh in your history.

!!
Repeat the last command in your history. Yes that is just '!!'. I can't post it as a code snippet for some reason.

!167


Repeat the 167th command in your history.


grep -ri <function name> .


Find all references to <function name> in files in the current directory and below, with a case insensitive match.

find . | grep -i <search>


Find all files and directories under the current directory with a case insensitive match on <search>. Useful if you don't really know what you're looking for, and you have only a phrase to go on. It's fast too.

sudo !!


Repeat the last command, except using sudo. Useful when you forget a command that you need to run as sudo.

df -h 


Human readable output of the disk space you have available on your drives.

du -h <directory>


Human readable output of the size of a given directory.

ln -s <source> <destination>


Create a symbolic link from <source> to <destination>. Think of symbolic links as aliases to files and directories which you can delete with rm without harming the original file.

tail -f <file>


This is one of the most essential commands I use. Use it on log files and anything else that changes frequently. It will update the display (follow) as new entries appear on the log file. Press space a few times to separate content if you want. Press control-c to stop tailing.

tail -f /var/log/*


This will tail follow all the files in /var/log.

watch ls


Takes you to a watch screen where the 'ls' command is executed once every 2 seconds, so you can monitor a directory for changes - new files etc.

Is This A Good Question/Topic? 6
  • +

Replies To: Intermediate Linux commands for developers

#2 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Posted 26 December 2011 - 07:27 PM

Cool, didn't knew about the !!

I don't know a lot of tricks myself, just common usage (most of time I'm trapped to an IDE :P)

history and watch are life saviors, I use df -h quit a lot too.



Just to add it, command line shortcuts can improve the command line usage experience too
Ctrl + a and Ctrl + e to navigate to beginning and end of line respectively
Ctrl + k to erase from cursor to end of line
Alt + f and Alt + b to navigate to next and previous word respectively

Not good as vi but less frustrating than using arrow keys and backspace :)

This post has been edited by anonymouscodder: 26 December 2011 - 07:29 PM

Was This Post Helpful? 3
  • +
  • -

#3 wordswords  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 272
  • Joined: 17-December 11

Posted 11 March 2012 - 04:38 AM

The shortcuts in which you navigate the current line can be definied by the 'set -o <preference>' command, ie:

set -o vi # gives you VI/VIM style shortcuts
set -o emacs # default, gives you emacs shortcuts

So you can have vi shortcuts to edit the current line :) To make this permenant, just put it in your .bashrc or .bash_profile.

This post has been edited by wordswords: 11 March 2012 - 04:43 AM

Was This Post Helpful? 0
  • +
  • -

#4 zomblake  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 27-June 12

Posted 27 June 2012 - 05:50 PM

!! sudo

This is such and awesome time saver. I don't know how much time I've wasted scrolling to the beginning long commands after arrowing up to the last command.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7648
  • View blog
  • Posts: 12,902
  • Joined: 19-March 11

Posted 27 June 2012 - 06:00 PM

Nice summary of some useful material. Well done.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1