Copy folder from one location to another by excluding specified folder .
- rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude
Create and Extract Archives
To extract a ZIP file, you can use:
-unzip archive.zip
To extract a Tar file, you can use:
-tar -xvf archive.tar
To extract a Tar.Gz file, you can use:
-tar -zxvf archive.tar.gz
To extract a Rar file, you can use:
-rar x archive.rar
To create tar.gz
tar -zcf archive-name.tar.gz foldername/
Note: The above will archive the entire folder foldername in an archive named archive-name.tar.gz in the current working directory.
Delete Files and Folders
To delete a whole folder and its content recursively, you can use:
-rm -rf foldername/
To delete all files/folders in the current directory, without deleting the directory itself, you would need to use:
-rm -rf *
Move and copy files and folders
The mv command syntax looks like this:
-mv original_file new_name
By executing the above command you will move (rename) the file original_file to new_name.
You can also use mv to move a whole directory and its content:
-mv includes/* ./
This will move all files (and folders) from the includes/ directory to the current working directory.
In some cases however, you will need to only update and move only files that were changed, which you can do by passing -u as argument to the command:
-mv -u includes/* admin/includes
The copy (cp) command works the same way as mv, but instead of moving the files/folders it copies them. For example:
-cp original_file new_file
The command will copy the original_file file to new_file and will preserve the original one (the file will NOT be removed after it is copied).
cp also accepts various arguments:
-cp -R includes/ includes_backup/
"-R" instructs cp to copy files recursively (for example, a whole directory). To overwrite already existing files you should use the -f argument:
-cp -Rf includes/ admin/includes/
- Log in to post comments