Linux commands

From Logicalwebhost-Wiki

Jump to: navigation, search
awk '/virus/ && !/OK/' scan.log | 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
cat /proc/version shows what version of Linux you're running
while read url ; do wget "${url}" ; done
chmod -R 777 * changes ownership of all the files below where you are to read-write-executable...not normally a super idea
cp -R * copies a folder and all it's contents somewhere
cp -ur --reply=y /somefolder/* /home/whateverdir/ copies all the file (updates only) to folder where we can back them up later
chown -R user.group * changes the owner and group of all the files below where you are
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
date uh, shows the date (and time), you can also run rdate -s ntp.nasa.gov to sync your machine
date -s "11/20/2003 12:48:00" sets the time
dd if=/dev/zero of=whateverfile bs=1000 count=0 creates a 10G blank file called whateverfile
dig -x 17.254.3.183 Reverse DNS on 17.254.3.183
grep <device> shows what's happening with a device, for more stuff, just run dmesg with no options. it shows all the hardware
du -hs * lists the directories below where you are and shows how much space they take
grep configure.php searches for configure.php
xargs grep -l '~olduser | xargs perl -p -i.OLD -e 's/~olduser/~newuser/g' How can I make a change to many of my files at a time? Use find and perl -p -i. For example, to change all occurrences of "~olduser" to "~newuser" in your HTML files, saving the original files with a .OLD extension, do
find / \( -type f -o -type d \) -a -perm -0002 lists all the files you have with too many permissions
find . -type f -print0 | xargs -0 chmod 644 chmod all the FILES below your directory, but not the folders
find . -type d -print0 | xargs -0 chmod 755 chmod all the FOLDERS below your directory, but not the files
find / -type f -size +500000k -exec ls -lh {} \; finds large files and displays filesize of them
fdisk -l displays all partitions on all hard drives.
grep -lr 'text_to_find' ./*
grep postfix access_log | grep 13/Sep/2007 | awk '{ print $1 " - " $11 }' | sort
looks for text_to_find in all files below where you are
history tells you all the commands that were run for awhile back
hostname sample.example.com sets the hostname to sample.example.com, if you just run hostname, it will show your hostname
hwclock --set --date="10/17/07 07:42:05" sets your hardware clock, if you want to see what it is first, just run "hwclock" first
ifconfig eth0 shows the config for eth0, in debian it's in /etc/network/interfaces, Redhat /etc/sysconfig/network-scripts/ifcfg-eth0
ifconfig eth0 192.168.1.2 netmask 255.255.255.0 up; route add default gw 192.168.1.1 sets your IP on eth0 with an IP of 192.168.1.2, netmask of 255.255.255.0, gateway of 192.168.1.1 and brings it up with that configuration
ifdown eth0 stops eth0
ifup eth0 brings eth0 up, so if you just want to restart eth0, you'd enter "ifdown eth0" and then "ifup eth0" after that
kill 3257 grep httpd and then do pidof httpd
lm-sensors monitors your system temps, etc. You have to install it, and then run sensors-detect (in Debian) to setup your system scanner. Then you can start it with /etc/init.d/lm-sensors start, then run the command sensors
grep rwxrwxrwx list folders that are 777, meaning anyone can write to them
lspci -v lists everything on the PCI bus
md5sum file.iso > file.iso.md5 create an md5 checksum for an iso, or you can use it for other files too, but .iso is the most common usage
md5sum -c file.md5 checks the file you just made against the original, it will say 'OK' if it checks out okay
netstat -a tells what stuff is running
netstat -i shows what your interfaces are doing
netstat -lpe shows you what ports are open, and what program is trying to use them
netstat -r shows your routing table
nmap -F -T5 -sS 1.2.3.4 scans for open ports on IP 1.2.3.4
nmap -sS -sU -sR -P0 -A -v 1.2.3.4 scans for TCP (sS) UDP (sU) portmap (sR) with OS/version detection (A) info and prints our Verbose (v) output on the machine at 1.2.3.4. Make sure you have permission to run this on their machine, otherwise you won't make any friends doing it :)
pstree shows a tree structure of what's running, really nice and a whole lot easier to use, you might have to install this
rdate -s time.nrc.ca sync's the servers hardware time, if you leave the -s out on Debian, it will show you the new time
route add default gw 192.168.1.1 sets up the gateway everyone will go to when looking for stuff on your upstream network. You can go nuts with the route command, like setting up multiple networks on different NIC's, but this should get you going :)
rsync -auv -e ssh username@192.168.1.1:* /localwhereverdirectory/ backs stuff up across a network to somewhere
rm -rf * kills everything, seriously, everything, honest, the big cosmic shredder, use with valium
scp localfile unclecameron@66.11.124.139:/remotefilename remote copy using ssh
sed -i -e 's/192.168.0.1/192.168.0.2/g' /etc/apache2/apache2.conf changes all instances of 192.168.0.1 to 192.168.0.2
tail -f maillog will view maillog realtime, so then you can see what happens when something happens
tail myfile.txt -n 100 shows the last 100 lines of myfile.txt
tar xfvz filename.tar.gz unzips, untars and gives you a folder named filename, you don't have to use a dask, or you can if you want, use -j instead of -z if it's a .bz or .bz2
tar -xjvf whateverbz2zippedfile.bz2 unzips a .bs2 archive file
tar -cvzpf archive.tgz ./whateverfolder zips a whole folder
useradd -d /var/www/ -g -G www-data thumper1 adds thumper1, but also puts him the www-data group, so he can sftp up to the site root on the server without apache giving the dreaded 403
users and groups tutorial here
wajig hold postfix keeps postfix from being updated when you use apt-get upgrade
which ssh shows where the executable for ssh lives
write root pts/2 sends message to someone after you run "who" and find them
Personal tools