This collection of commands are some of the commands I have learned in these years. Of course I am not the author of them, as no one is the author of any command in Linux. I have found some of them in differente pages, and modify some of them, others I have "created" by myself. Reading books, or man pages. Disclaimer: Try any of these commands, in non-production servers, some of them may break something Add yours in the comments.
Purge configuration files of Debian's removed packages
There are different ways to do this, these are some options.sudo aptitude purge '~c'
sudo dpkg -l | awk '/^rc/ {print $2}' | xargs dpkg -P
Create movies from jpg files
mencoder "mf://*.jpg" -mf fps=10 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800
Empty (erase contents) of a file
Once again there are different ways to do this::> file
truncate -s0 file
Find duplicate files, based on size and MD5
find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
Replace space on file names with underscores
#!/bin/bash
ls | while read -r FILE
do
mv -v "$FILE" `echo $FILE | tr ' ' '_' `
done
Convert a man page to txt file
man cp | col -b > /tmp/man-cp.txt
change cp for any command you want to have its man page in text format.
List the most used commands in your history
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
Execute a command, and do not save it in history
command
Attach a clock to the command line prompt
export PS1="${PS1%\\\$*}"' \t \$ '
The output will look like this:[ggarron@arch ~] 16:13:14 $
Force file system check
sudo touch /forcefsck
orsudo shutdown -rF now
Create and mount a RAM disk
mount -t tmpfs tmpfs /mnt -o size=1024m
That will create a 1 Gig RAM disk, that you can use to have fast access to files there, just remember is a RAM disk, and all its contents will be deleted when the system is rebooted.
Call commands from History
You may call command from history by numbers:class="codigo">history
963 du -h
964 ls
965 df
966 htop
967 df -h
968 df -h
969 history
Then using the number call a command:!963
Or call it by using the first letters:!df
This last method, is somehow dangerous, as you do not know what arguments and options the command is going to use, so, you can pause it. Using this way is safer:!df:p
It shows you the command but do not run, it, then, you can run it without the :p and it will run, but this time you know the options.
Count lines and words in a text document
wc -l -w mytextfile.txt
Mount a remote file system via ssh
sshfs remote-user@remote.server:/remote/directory /mnt/remote-fs/
More info: here
Copy ssh public key to a server to access it with no ssh password
cat ~/.ssh/id_rsa.pub | ssh user@remote.machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
More info: here
Generate random passwords
dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64
With 16 characters, if you want only 8.dd if=/dev/urandom bs=8 count=1 2>/dev/null | base64
Update Twitter from the command line
curl --basic --user "user:pass" --data-ascii "status=Arriving the office" "http://twitter.com/statuses/update.json"
Replace words in a document using sed
sed -i 's/OLD/NEW/g' FILE
More info here
List type of network connections active and the number of them
netstat -ant | awk '{print $NF}' | grep -vE '[:upper:]'| sort | uniq -c | sort -rn
Output:35 TIME_WAIT
27 ESTABLISHED
2 LISTEN
2 CLOSE_WAIT
Mount an iso image as disk
mount -t iso9660 -o loop file.iso /media/disk
Reset the terminal, when it get screwed, and you can only see garbage on it
reset
List all processes with stablished connections
lsof -i -n | grep ESTABLISHED
More info here
Backup a disk or partition to an image
dd if=/dev/sda of=~/backup-disk-YY-MM-DD.img
More info here
Simple HTTP server to share files
python -m SimpleHTTPServer
Change the layout of you keyboard on the fly
setxkbmap -layout us
Read a compressed file on the fly, without uncompressing it
zcat file.gz
Use lynx to store web pages as text
lynx -dump http://www.go2linux.org > $HOME/go2linux.txt
Determining the type of file
file *
make commands keep running after leaving a terminal session or ssh session
nohup nice -n 4 [command] > output.txt &
More info here
Recreate fluxbox menu
fluxbox-generate_menu
No comments:
Post a Comment