2 | Genral Purpose Command (New linux user) | ||
ls | ---- list items | ||
cd or cd/.. | ---- change the directory | ||
sudo nano <path> | ---- go to editor for change settings | ||
sudo service nginx restart | ---- to restart nginx server | ||
sudo chmod -R 777 /usr/share/nginx/html | ---- to change access | ||
sudo service php restart | ---- to restart php server | ||
traceroute <websiteName> | to find ip address of a website | ||
sudo -s (gives the root access) apt-get -f install install your packege |
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? |
||
find . -cmin -20 | grep -rni . -e 'insertTestQuestion' | USED TO FIND PERTICULER WORD IN FILES | https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux |
File Permission Table Absolute(Numeric) Mode | ||
Number | Permission Type | Symbol |
0 | No Permission | --- |
1 | Execute | --x |
2 | Write | -w- |
3 | Execute + Write | -wx |
4 | Read | r-- |
5 | Read + Execute | r-x |
6 | Read +Write | rw- |
7 | Read + Write +Execute | rwx |
grep command |
||
used | command | explanation |
grep input ,count & number format o/p | grep -l -r -i "getAllPendingData" . | grep -n . | wc -w | count all with input string and o/p will show in format of number of file |
grep and sort | ls -lt | grep 'Dec 8'| wc -l | sort date wise and count number of files |
grep all files | sudo grep -l -c -rni 'getAll' | search all file with getAll |
greap and list | grep -l -c -rni "getAllPendingData" > list | used to search perticular word in directory and create list |
grep in specific files | input: grep -r --include="*updatePerf*" "\`incorrectQuestions\`=incorrectQuestions + 1,\`modifiedOn\`=UTC_TIMESTAMP() WHERE userId =74" . | wc -l output : 88 |
|
grep -l -r --include="*updatePerf*" "correctQuestions - 1,\s*\`incorrectQuestions\`=incorrectQuestions + 1,\`modifiedOn\`=UTC_TIMESTAMP() WHERE userId =74" . |
archive command | ||
used | command | explantion |
tar archive | tar -czvf logs.tar.gz folderName/ | create tar file with name logs |
tar extract | tar xvzf logs.tar.gz -C folderName/ | extractn logs.tar.gz to perticular folder |
Size Related Command | |
command | usage |
df | The df command shows the disk space usage on all the currently mounted file systems. |
df -h | As well as physical hard drives, df also lists other types of mounted filesystem, most notably the udev filesystem for /dev and the tmpfs filesystem for /run and its subdirectories. These are file systems that run in memory and are part of the internal workings of Linux. For example, /run/lock is a place for processes to create lock files (to ensure orderly access to certain resources), for speed they are created in memory rather than on a physical disk. Likewise, the Linux device manager creates the special device files needed by the kernel in /dev directory. |
du | disk usage command |
du -h --max-depth=2 |
give n folder size upto 2 folder limit |
sudo du -x / | sort -n | tail -40 | sort when disk id full and shows acual space of folder |
du -h -d 2 -c | Report total size of disk |
du -h -d 2 -a | show disk usage of files |
du -h -d 1 | space show and usage of disk |
find Command | ||
used | command | explanation |
find and count file | sudo find . -name "*error *" | wc -l | for in perticular dir and count number of file |
find and move file commad | sudo find . -name '*.html' -exec mv -t /data/production_logs/ {} + | find name of file in dir and move to dir |
find & Copy | sudo find . -name "*usererror*" | xargs cp errors/ | find name of file in dir and copy to other dir |
find & tar/zip | sudo find . -iname ".html*" -exec tar -rvf file.tar {} \; | find file name and create archive of all file in dir |
find and delete | sudo find . -name "*GetS*" -delete | find and delete perticular file |
#files by extension | find . -type f | sed -n 's/..*\.//p' | sort | uniq -c | get number of files by extension |
find perticular word in last 20 min | find . -cmin -20 | grep -rni . -e 'insertTestQuestion' | how many times perticular word is repeated is check by this command |
find for perticular time and delete | find -newermt "mar 13, 2018 10:59" -not -newermt "mar 13, 2018 15:00" | wc -l | find file name and and delete in perticular time |
remove command (Used only with expert advice) | ||
used | command | explantion |
remove dir/file | sudo rm rf folderName/ | remove dir permantally |
remove 'cat list' | rm -f 'cat list' | remove cat name list if already created |
create list and remove | sed -i -e 's/^/rm -f /' list | sed create list of file rm remove |
nginx command | ||
command | used | genrally used when occers this prolem on server |
sudo service nginx restart | restart service of nginx server | used for restart server when 502 or 504 gatway occures |
sudo service php5.6-fpm restart | restart service of php process | used for on restart server when 502 or 504 gatway occures |
sudo service mysql start | start mysql | used for start mysql server (it has not restart option) |
sudo serive mysql stop | stop mysql | used for start mysql server (it has not restart option) |
Problem where clause not working in linux | Issue | |
group by clause is not working in ubuntu | showing incompatible with sql_mode=only_full_group_by error | |
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set | internet, sudo command is not working |