Here’s a list of Linux commands I found very useful throughout the years. You might want to bookmark it as you’ll surely need it again someday.
Archive files of folders:
tar -czf new-tar-file-name.tar.gz file-or-folder-to-archive
tar -czf new-tar-file-name.tar.gz file1 file2 folder1 folder2
Unarchive:
tar -xzf tar-file-name.tar.gz
List and sort files by size:
ls -lS
ls -lSr
List folder sizes:
du -sh /*
Show free disk space:
df -h
Count all the files and folders in a directory:
ls | wc -l
Rename a file or folder:
mv name new_name
Remove an entire folder, with all its content:
rm -rf dir_name
Create a symlink:
ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]
E.g.:
ln -s /usr/local/apache/logs ./logs
Convert windows stye line-endings to unix style for an entire project:
This command will skip the .git and .svn directories but you can adapt it to your needs:
find . -path ./.git -prune -o -path ./*.svn -prune -o -print -exec dos2unix {} ;
Find files containing text:
grep -rnw 'directory' -e "pattern"
and here’s an example:
grep -rnw /etc/apache2/sites-available/ -e "www"
Find (then delete) .svn folders form your project:
find . -name .svn -exec echo {} ;
find . -name .svn -exec rm -rf {} ;