Linux/Linux Command Cheat Sheet

From EasyWebDNS
Jump to: navigation, search

Here i will be compiling a list of Linux commands that i often use, When the list is comprehensive, i will post it to the Linux tutorials area

Most of the commands are for a command line interface for Linux and Unix systems called BASH (Born again Shell), Some are on how to use popular applications like bzip2 and TAR

Command What it does Notes
File and Directory
ls list all files and folders in directory
ls -l list the files with details
cp file1 file2 Copy file 1 to file 2 (file 2 new file)
cp -R /path_to_directory/directory_tocopy/ /pathtodestination/ Copy the Folder/Directory directory_tocopy inside pathtodestination including all subfolders and files, the R stands for recursive Notice that after this copy (cp) operation, a directory of the name /pathtodestination/directory_tocopy exists
mv file1 file2 move file1 to file2 its a copy then delete source, thats how it really works (Some new methodes change the file index rather than physically moove it)
cat > file.txt (hit enter) write the file contnet to terminal, then CTRL+D to close it a simple way to create a text file from the prompt
more file.txt Display the contents of the file to the terminal (read to terminal) will give you a scroll down ability
rm file delete a file....
df -h Displays a short report on disk usage. Shows every hard disk's usage, and displays that drive's system name for an identifier

Sample Output

Filesystem Size        
/dev/sda3 228G 53G 164G 25% /
/dev/sdb1 668G 16G 638G 3% /mysecondhd
/dev/sda1 99M 34M 61M 36% /boot
none 1013M 0 1013M 0% /dev/shm

The last drive (none) is Shared Memory drive.

sda is the first hard drive (showing 2 partitions aboe, sdb is a second one partition hard drive.

You should probably note that S is for SATA drive (Serial ATA), Paralel ATA drives will show as hda and hdb not sda and sdb

rm -rf ./directory Delete directory and all its sub folders Very Dangerous, No confirmation, Root user can delete entire disk !
du -bs /dir1/subdir The size of the given directory in Bytes (-b) Check out the command du and what other formats are there for output
tar --create --verbos --file=myfile.tar directory Tar entier directory Directory can be a name or a full path, --verbos is to list files that are being added
tar -cW M (tar -c -M --tapelength=sizeinkbs --file=disk1.tar alargefile) Multipart tar to a tape drive for example
tar -xvf myfile.tar Extracts all files in myfile.tar to curent directory
tar cvzf Tar with GZ compression
bzip2 -z -k filename Compress the file filename z is for compress and k is for do not delete input file
Session
logout ctril+d (or exit to quit the login)
passwd Change Password Old, New, New again
hostname Show host name
history View user command history
history | grep logout Search history for logout
whoami Displays your username
who list all logged in users
w Lists who is logged in and what they are doing
last List of recent system use
last ausername Display last login for user
ps list the processes in your shell session
ps -u someusername List all user processes
ps aux list all processes and display username
top show a constantly updated list of system processes
top -d 3 Update the list every 3 seconds
ps aux | grep sbin list all processes with referance to sbin in there command
ps aux | grep 10 Display all processes with ids containing the number 10
whoami --help
man display the manual
info View all info manuals on the system
info -f infofilename Read an info file from curent directory
chmod -R 0777 dir CHMOD directory and all contents to 0777 The R stands for recursive, take it out and no longer recursive
rpm -qi sendmail install sendmail rpm just an example
free Display memory usage free -m will display the usage in MB rather than the default KB
~# free -m
            total       used       free     shared    buffers     cached
Mem:           512        262        249          0         57         94
-/+ buffers/cache:        110        401
Swap:         1499          0       1499

The -/+ buffers/cache: shows you how much memory is really free and is in use after subtracting the cache and buffers from the totals above, on the example system, 110MB is used out of 512

To free the cache

echo 3 > /proc/sys/vm/drop_caches
MySQL
mysqldump --opt -u mysqluser --password="userpass" databasename > file.sql Dump mysql Database mentioned to SQL file Needs MySQL privilages
mysqldump --opt -u mysqluser --password="userpass" --all-databases > file.sql Dump all MySql Databases to a file Needs MySQL privilages
mysql -u username --password="userpass" destinationdatabasename < file.sql Restores a database
mysql -u mysqluser --password="userpassword" < file.sql Restore an entier database dump (multiple dbs) Nothing behind the < except for the casual ordinary space
Finding Out about your computers processor

LINUX:
cat /proc/cpuinfo

BSD:
dmesg | grep cpu

Domain Search:
.COM$ 8.49
.NET$ 6.49
.ORG$ 7.49
.INFO$ 1.99
Compare Pricing
Cheap Domains
Personal tools