Linux Command Line
Here are a few Linux commands I often forget, but find very useful
1. Disown
So you started something running on a machine but then realize that you want to go home, that means you should have started it prefixed with nohup, so when close your terminal window the application still keeps running. However once you’ve started an application, you can use “ctrl+z” “bg” and then “disown”
chris@mango:~> sleep 1000 ^Z [1]+ Stopped sleep 1000 chris@mango:~> bg [1]+ sleep 1000 & chris@mango:~> disown chris@mango:~>
Now you can close the terminal down, if we open up another terminal and look at the running jobs
chris@mango:~> ps -e | grep sleep 16334 pts/0 00:00:00 sleep chris@mango:~>
you can see it’s still running.
2. Search and Replace in multiple files
There are many ways to do this, here is a way using sed
This replaces hello with goodbye in all php files recursively.
If your need to use a # symbol in the search/replace code just replace all 3 hashes with some other character (such as colon: pipe| or forward slash/ )
find . -type f -name “*.php” -exec sed -i “s#${search}#${replace}#g” {} \;
3. What do I need to speed up
Not always obvious, but “What commands do I use a lot, so I can look at write scripts or aliases to speed them up?”
history |tr '\011' ' ' |tr -s " "| cut -d' ' -f3 |sort |uniq -c |sort -nbr |head -n10
This will extract from your history your top 10 most used commands.
Increase your history length by adding
HISTSIZE=10000 #or whatever length you need
to ~/.bashrc
If this has been useful to you, and you would like to buy me a coffee, or help towards my monthly server costs please click here to make a donation via paypal.
















Recent Comments