Useful Linux commands I can never seem to remember
This is just an ongoing list of Linux commands I keep having to look up. I’ll be updating this list as things come up.
Compress & uncompress (tar.gz) a directory
Compress: tar -zcvf archive-name.tar.gz directory-name
Uncompress: tar -zxvf archive-name.tar.gz
Return Path for all directories of a given name (directory search)
find / -type d -name ‘DIRECTORYNAME’ -ls
File which specifies a servers root http path
/etc/httpd/conf/httpd.conf
Restart after making changes by running: /etc/init.d/httpd restart
Count number of files in a directory
cd to the directory
ls -1U */ | wc -l
Check directory size
du DIRECTORY
result is in KB
Copy a file from one machine to another
scp -P MACHINE_PORT_NUMBER -p FILE_TO_BE_COPIED USERNAME@MACHINE_IP:NEW_LOACTION
example: scp -P 22 -p file.php admin@255.255.255.255:/home/admin
Change file owner
chown NEWOWNER FILENAME
example: chown nobody index.php
Remove a directory and all files inside
rm -rf direcotory_name
Get size of directories
du -h (all directories and subdirectories in the current directory)
du -sh (total of current directory)
du -sh (all files and directories in the current directory)