Logicalwebhost Cheatsheet

Linux & Open Source Cheatsheets & Howto's

Skip to: Content | Sidebar | Footer

linux commands

8 January, 2011 (01:40) | linux commands | By: unclecameron

sets the time

command what it does
awk ‘!/virus=””/’ > sometextfile pipes notification of nasties to a text file called sometextfile
cat /proc/cpuinfo shows what CPU is installed
cat /proc/meminfo shows your memory stuff (or just type “free”)
cat /proc/version shows what version of Linux you’re running
chmod -R 777 * changes ownership of all the files below where you are to read-write-executable…not normally a super idea, 755 is slightly better, or 644 much better
cp -R ./* /some/other/place/ copies recursively from where you are to /some/other/place/ folder you specify
cp -ur –reply=y /somefolder/* /home/whateverdir/ copies updates only to someplace you specify
chown -R user.group ./* changes ownership of user and group for all the files recursively from where you are, just pick your user and group
cut -b 42- photos.txt > photoscut.txt cuts off the first 42 characters in the lines in photos.txt and puts the cropped data in photoscut.txt
(pv -n /dev/sda | dd of=/dev/sdb bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0 copies the WHOLE drive of /dev/sda to /dev/sdb. Not just a partition, but a bit-for-bit thing. The rest of the command gives you a nifty progress bar, because dd takes a long time very often. Dd is really blunt instrument, if you don’t know what you’re doing you can easily lose ALL of your data, like if you pick the wrong drive or something. Use fdisk -l to tell what disks you have, and make triple sure you’re selecting the right one. You’ve been warned.
dd if=/dev/sdc of=/path/to/new.iso turns a disk into an .iso, in this case /dev/sdc, but make sure you’re using the right drive
date -s time.nrc.ca sets the date to internet time, or just tells you the date if you type “date” only
lsof -i shows who’s connected, and to what
lsblk shows what’s on your drive like: >: lsblk
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 48G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 2G 0 part [SWAP]
sr0 11:0 1 2K 0 rom
date -s “11/20/2003 12:48:00”
dd if=/dev/zero of=whateverfile bs=1000 count=0 creates a 10G blank file called whateverfile
dig -x reverse DNS on
du -hs * lists the directories below where you are and shows how much space they take
find / -type f -size +500000k -exec ls -lh {} \; finds large files and displays filesize of them
rdate -s tick.greyware.com sets local hardware time to the standard time on the remote time server on greyware.com
route add default gw adds a default gateway when other things fail to do so, you’ll need one
rsync -auv -e ssh username@* /localwhereverdirectory/ syncs all the files over encrypted protocol in the home directory of to the current directory on the machine you type this on, but only newer instances if their is a same file in the source and destination directories.
screen opens a new ‘virtual terminal’ so once you log out, it will keep whatever you’re doing in that terminal still open and running – very useful if you have a flaky Internet connection
screen -ls lists screen sessions that might still be running, should give you something like: 8337.pts-1.machinename , which you then can re-attach to
screen -r 8337.pts-1.machinename reattaches to and old screen session 8337.pts-1.machinename, but ONLY if it’s detached, if it’s still attached you have to use screen -X
screen -X 8337.pts-1.backup1 reattaches to a screen session that still says ‘attached’
sed -i -e 's/' ./db* replaces all the instances in all the files in the current directory starting with db with
tar -cvzpf archive.tgz ./whateverfolder zips (.tgz) an entire folder (change to suit folder name)
tar -xJvf file.pkg.tar.xz unzips a whatever.xz file
tar -pczvf archive.tar.gz ./somefolder does same thing, but with tar.gz
tar -xjvf whateverbz2zippedfile.bz2 unzips a whatever.bz2 file
umount -l /dev/sda1 forces umount to unmount a filesystem when it says it’s busy, but isn’t (make sure first)
watch -n .1 cat /proc/mdstat keeps track of a file in realtime, sort of like tail -f

Write a comment

You need to login to post comments!