05 August 2015

Linux Basic command line

Linux Commands

  • Permission and ownership
chmod
- r is for read permission = 4
- w is for write permission = 2
- x is for execute permission = 1

chown
- u is for user
- g is for group
- and o is for others
Ex:
chmod -R 755 directory-name
chmod u+x filename

chmod Examples
Give read, write and execute to everybody (user, group, and others)
read, write and execute = 4 + 2 + 1 = 7.


  • Files & Foders Delete and Transfer
rm;
ex: rm file-name.tar.gz
scp
our-manchine <-- server
scp root@server-name:/root/dbbackup/latest001.tar.gz /home/user-name/Desktop/
our-manchine --> server
scp /home/user-name/Desktop/latest001.tar.gz root@server-name:/root/dbbackup/
  • Database
mysqldump;
ex: mysqldump  -u dbuser -p dbname > dbname.sql
  • Zip and Extract
tar;
Create archive folder1 and foder2 into one zip
tar -czPf  folder-name.tar.gz  folder1 folder2
Extract folder-name.tar.gz
tar -xvf  folder-name.tar.gz
  • Grep content
$ grep -lir 'DB_USERNAME' .
$ grep 'word' filename.txt
grep;
ex: grep 'word' filename.txt

  • File View
cat
head
ex: head -n 15 |tail -n 5 file.txt
tail
more
less
  • Find File and Folder
whereis
find
locate
  • Check File Folder Size
du;
ex: du -h  filename.tar.gz