
UBUNTU – Useful and basic commands
If you are working on an ubuntu linux OS, those command would be pretty useful for you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# Remove files with a precisely extension. find . -type f -iname \*.jpg -delete # Copy an entire folder with its contents cp -a <source> <destination> # List installed packages related to something dpkg -l | grep <filter_description> # Show n lines before and after, on a grep cat <file_to_inspect> | grep -C10 '<description_to_filter>' #will show 10 lines above and below your description cat <file_to_inspect> | grep -B10 '<description_to_filter>' #will show 10 lines before your description cat <file_to_inspect> | grep -A10 '<description_to_filter>' #will show 10 lines after your description # Remove first n lines from a large file (eg: 43 first lines) tail -n +43 <file> > <file_2> # Get last n lines from a large file (eg: 43 last lines) tail -n 43 <file> > <file_2> # Replace all occurrences of a string on a large file sed -i 's/<original_str>/<new_str>/g' <file_name> # Replace an string in multiple files ("foo" will be replaced by "bar") cd /path/to/your/folder sed -i 's/foo/bar/g' * |
To manipulate, and compress/uncompress files or directories:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Compress a directory or files tar -zcvf backup.tar.gz directory-you-want-compresss/ tar -zcvf backup2.tar.gz file1 file2 file3 # Uncompress a directory or files tar -xvf backup.tar.gz directory-you-want-uncompresss/ ## Working with ZIP / RAR files sudo apt-get install zip # Compress zip/rar file zip backup.zip directory-you-want-compresss/ zip backup.zip file1 file2 file3 # Compress zip/rar file unzip backup.zip directory-you-want-compresss/ unzip backup.zip file1 file2 file3 |
How to find the path of a file based on its name
1 |
locate -br '^<filename.extension>$' |
In order to work with mysql databases
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# Create a dump for your database mysqldump -u user -p'password' DBName > your-dump-file.sql # Import a dump file cd /path/to/your/assets/folder mysql -u user -p'password' create dabase new_database_name; use new_database_name; source your-dump-file.sql; # Export just one table mysqldump -u user -p'password' DBname TableName > your-dump-file.sql # Import just one table mysql -u root -p'password' DBname < your-dump-file.sql # logged to mysql service: SHOW DATABASES; # Show all databases. SHOW DATABASES LIKE '%<filter>%'; # Show databases which names corresponds to the filter. use <db_name>; SHOW TABLES; # Show all tables in used database SHOW TABLES LIKE '%<filter>%'; # Show all tables which names corresponds to the filter. |
Copy files via SCP (Secure copy)
1 2 3 4 5 6 7 |
# You need to use your ssh credentials to operate via scp. # To upload a file scp newfiles.tar.gz <sshuser>@<sshdomain>:<destination path> # To download a file # (if you are running the command wherever you want the file, just use . as <local destination path>) scp <sshuser>@<sshdomain>:<server origin file path> <local destination path> |
Find text inside files
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Find a simple text inside files of directory grep -rnw '/dir/to/look' -e 'pattern' -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. # This will only search through those files which have .c or .h extensions: grep --include=\*.{c,h} -rnw '/dir/to/look' -e "pattern" # Also, you can exclude directories on your search grep --exclude-dir={dir1,dir2,*.dst} -rnw '/dir/to/look' -e "pattern" |
MD5 Encription of a file
1 |
md5sum <your_filename> |