Posts Tagged ‘ Linux ’

Common Linux Command

Linux / Unix command

ls command in linux (ls) – to view content
ls -l -> view all details of folders content
ls -lh -> view all details of folders content with readable filesize
ls -l /etc -> view all details of /etc’s content
ls -lt -> view all details of folders content based on time modified

Top command in linux (top) – display top CPU processes
top -c -> display top CPU processes with detailed command
top -H -> display all threads
See http://linux.about.com/od/commands/l/blcmdl1_top.htm

Moving Files (mv)
mv file.txt /folder -> move file to new location
mv file.txt ../ -> move file back one directory

Copying Files (cp)
cp file.txt /folder -> copy file.txt to a folder
cp folder1/file1.txt folder2/file2.txt -> copy file1.txt as file2.txt
cp *.txt /folder -> copy all .txt extension to a folder
cp * /folder ->copy all file to a folder
cp -a /folder /newfolder ->copy a folder and content to a new folder

Remove or Delete Files (rm & rmdir)
rm file.txt -> remove a file
rm -r /folder -> remove a folder and all its content (recursive)
rm -rf /folder -> force remove a folder and all its content (recursive and force)
rmdir /folder -> remove a folder

Making a Directory (mkdir)
mkdir folder -> create a folder

Transfer files to server (scp)
Warning: Be careful when copying between hosts files that have the same names. You may accidentaly overwrite them.
scp file1.txt user@userhost.com:location -> copy file1.txt to user@userhost.com:location
scp -r user@userhost:location /folder -> copy all content of user@userhost:location to a folder (recursive)
scp user1@userhost1:file1.txt user2@userhost2:location -> copy userhost1 file1.txt to userhost2’s location

Zip Files using zip (zip)
zip file.zip file1 file2 file3 -> zipping file1,file2 and file3 to file.zip
zip -r file.zip /folder -> zip folder to file.zip (recursive)
unzip file.zip -> unzip your zip file called file.zip

Using tar
tar cvf name_of_your_archive.tar folder/ -> tar folder/
tar xf name_of_your_archive.tar -> Extracting tar file
tar -pczf name_of_your_archive.tar.gz /path/to/directory -> compress /path/to/directory to name_of_your_archive.tar.gz
tar -xzf name_of_your_archive.tar.gz -> Extracting name_of_your_archive.tar.gz

Change owner and change group of a file (chown & chgrp)
chown owner file -> change owner of a file
chgrp group file -> change group of a file
chown owner:group file -> change owner and group of a file
chown -R owner /folder -> change owner of the folder and its sub folder (recursive)
chgrp -R group /folder -> change group of the folder and its sub folder (recursive)
chown -R owner:group /folder -> change owner and group of the folder and its sub folder (recursive)

Changes the permission of a file (chmod)
chmod 644 file -> change permission to file
chmod -R 644 /folder -> change permission to folder and its content
See http://www.suite101.com/content/linux-commands-changing-permissions-with-chmod-a82401

Searching files (locate)
locate file -> locate file globally
locate file /folder -> locate file from folder

Searching Process (ps)
ps aux | grep java -> show all process called java
ps auxwww -> show all process and its details

Size of folder(du)
du -hs /path/to/directory -> Show total size of the folder

Linking folder(ln)
ln -s /path/to/directory -> Linking to another folder w/o copying them

More about linux see http://en.wikipedia.org/wiki/Linux