This document provides a cheat sheet of Linux command line shortcuts and commands useful for web developers. It includes sections on usage shortcuts, system commands, navigating directories, file transfer, searching, files and permissions, installations, and web developer administration. The cheat sheet lists over 50 common Linux commands and their basic usage.
This document provides a cheat sheet of Linux command line shortcuts and commands useful for web developers. It includes sections on usage shortcuts, system commands, navigating directories, file transfer, searching, files and permissions, installations, and web developer administration. The cheat sheet lists over 50 common Linux commands and their basic usage.
Linux Command Line Cheat-sheet stevenmccullagh.com
for web-developers
Usage Shortcuts System Commands
Press to see the previous command you typed. df Disk free space, eg: df -h tab Press once to auto-complete file/directory names pwd Print working directory (your current location) tab-tab Press twice to see a list of possible auto- users Print all users of the system completions of file/directory names screen Resume terminal window on remote system Eg: / Root directory. Eg: cd / screen (initiate), screen -d (detach) screen -r ~ Home directory. Eg: cd ~ (reconnect) exit (exits a screen) . Current directory Eg: cd ./images du Disk usage of any file or directory .. Parent directory Eg: cd ../ Eg: du -ach images/ (a=all, c=total, h=human readable) ctrl a Moves cursor to beginning of line /proc/meminfo Detect system RAM. ctrl e Moves cursor to end of line Eg: grep MemTotal /proc/meminfo ctrl r Remember a command you typed earlier. Eg: Ctrl r rsync (if you used rsync yesterday) /proc/cpuinfo Detect CPU information ctrl c Forcefully end a process or task Eg: grep "model name" /proc/cpuinfo ctrl d Gracefully end a process or task cron Scheduled tasks. Make a file to be executed, and make a cron file in the following format: help Get help with the program you are trying to run. Eg: mkdir –help or mkdir –help or mkdir –h minute hour day(of month) month(1-12) weekday(0-6) path-to-file-to-execute.php or ftp example.com Eg: 0 1,2 * * * /myfile.php Will run at 1and 2am help every night. Save this text file. Then run: man See the user manual for the program you are cron myCronInstructionFile.txt (to install the more View a file (linear read only, press spacebar to crontab) progress) whereis Find a service, Eg: whereis mysql Eg: more myPhpFile.php alias Define shortcuts for long instructions: less Like more but can navigate forward and backward Eg: alias ls='ls -F' through the file (use spacebar to go forward, and b (will run ls –f every time you type ls). Or make a to go backward) file containing all aliases called .bash_aliases
Navigating Directories File Transfer
cd Change Directory. wget Download public files from other servers. Eg: cd /var/www/vhosts/example.com/httpdocs Eg: wget http://www.example.com/file.jpg (to navigate to your website files) Download whole website: ls List all files and directories in the current directory Eg: wget -r -l 0 http://www.example.com/ ls -al List all files and directories, with more information Download title page, images, css and make local (or ll) references: ls –lSr List files biggest first Eg: wget -p -k http://www.example.com/ ls with grep Filter the result set based on search: ftp Eg: ftp example.com Eg: ls -l grep *.php myUserName Or: ls grep index* myPassword mkdir Make a directory Eg: mkdir myFolder cd /var/www/toToYourPreferredDirectory rm Remove File or Directory. lcd c:\temp\gotoYourPreferredLocalDirectory Eg: rm myFolder (if empty) get filename.php (upload this file) Eg: rm myFolder –fr (if not empty and has sub- put other.php (download a file) directories, f=force, r=recursive) ssh/scp Connect via SSH, then do secure copy transfer: unlink Delete a file. Eg: unlink myFolder/myFile.txt or ssh [email protected] unlink myFile.txt e.g. scp example.com /putFilesHere or cp Copy a file. scp /getFileFromHere example.com/ Eg: cp myFile.txt myFolder/myFile.txt (takes format of from then to) rsync Download files from one machine to another by SSH login to remote machine. mv Moves a file Eg: mv myFile.txt myFolder/myFile.txt Eg: rsync -e ssh -avz [email protected]:/var/www/html Searching Files & Permissions find Find files. Eg: find myFile.php chmod Change mode of a file or directory. locate Find files on the system (only includes files present Eg: chmod 777 myFile.php last time updatedb was run. Should be set as daily chown Change the owner of a file or directory. cron job). Eg: chown root myFile.php or chown –R root myDir/ (R=recursive) chgrp Change the group-ownership of a file or directory. Installations Eg: chgrp root myFile.php or .\ configure Configure the program before installation to chgrp –R root myDir/ identify any dependencies Rename for old in *.php3; do cp $old `basename $old make install Install the program, and delete the installation multiple files’ .php3`.php; unlink $old; done make clean files when complete extensions or Eg: rename php3 php *.php3 (rename all php3 rpm Install an rpm (packaged program) for your OS and files to php in anyfile matching *.php3) hardware. Eg: rpm –ivh packagename (to install an RPM) Eg: rpm –Uvh packagename (to upgrade an RPM) Compression & Archives Eg: rpm -q -a (to see all installed RPMs) tar Make or Extract tar files. Eg: tar –xvf myTarFile.tar (extract) which Identify the executable file in a directory Eg: tar -cvf tar1.tar images/ (make a tar file out Eg: which ./ of your images directory) Eg: tar –czvf tar1.tar.gz directory/ (make .tar.gz) Web Developer Administration Eg: tar –cjvf tar1.tar.bz directory/ (make .tar.bz) service Restart Apache, eg: service httpd restartRestart bzip2 Compress/Decompress files using bzip MySQL, eg: service mysql restart Eg: bzip2 tar1.tar (compresses the tar file you just mysql Repair DB. Eg:/usr/bin/mysqlcheck -A -p –repair made into tar1.tar.bz) Backup DB: /usr/bin/mysqldump -B myDB-u Eg: bunzip2 tar1.tar.bz (decompresses the file myusername -p > myDB_backup.sql again) Restore DB: cd usr/bin/ ./mysqldump -B myDB -u zip Compress/Decompress files using zip myusername -p < myDB_backup.sql Eg: zip –r myzipfile images (to make myzipfile.zip php Output phpinfo() Eg: php -i from the images folder) or zip –r myZip .* * (zip Find php.ini file: whole dir) Eg: locate php.ini or Eg: php -i grep php.ini Eg: unzip myZip (to unzip the myZip.zip file into ftp Add FTP user, Eg: the current dir) adduser newUsername then passwd newUsername DNS & Networking host Get information about a domain name or ip Delete FTP user, eg: userdel -r newUsername host –mx Lookup the MX records for a domain or ip netstat Print network connections and routing tables ping Ping example.com or ping 212.241.194.1 Vi – Text Editor traceroute traceroute example.com open Load a file into vi. Eg: vi myFile.php whois whois example.com close Hit Esc. Press :q (do use the colon) Flush DNS To flush the DNS settings, save and close Hit Esc. Press ZZ or :q (and follow warning) use:/etc/rc.d/init.d/nscd restart exit without Hit Esc. Press :q! nslookup See DNS configuration of your system. save Eg: nslookupset type=mx save as… Hit Esc. Press :w newFileName.php example.com (to look up mx records) edit file Type a or I to enter edit mode. or undo u set type=a search / (search downward) example.com (to look up a name records) ? (search upward) Escape the following characters with \ if used in a ifconfig Get your ip addresses search: ^ * . $ [ > < Eg: /sbin/ifconfig /code (find the word code) n (next occurrence) N (previous occurrence)