Copying or moving files via terminal or command line are quite easy and basic.
Working remotely in Linux can be done by typing via terminal and executing commands.
Typing the same commands all over again is not quite practical, so a lazy admin comes into play.
Lazy admin doesn't literally mean a lazy admin, but a guy who likes to automate things by using his knowledge and skills like scripting.
Crontab in Linux is a scheduler to automate and run scripts at a specified time.
Crontab is powerful if the script and the settings are configured properly; it will do the task without user intervention.
Some basic commands below to move or copy files and pipe to "xargs" command.
By typing: ls *.log this will filter the output for files with ".log" extension.
ls *.log | mv $(xargs) /path/another_folder
Move Recursively:
find /path/log_folder/ -type f -name '*.log' | mv $(xargs) /path/another_folder/
If filenames are the same files command will prompt to overwrite.
Move Recursively:
find /path/log_folder/ -type f -name '*.log' | mv $(xargs) /path/another_folder/
If filenames are the same files command will prompt to overwrite.
Command above will move ".log" files to the folder specified. It doesn't need to specify a file name.
To just copy the files for redundancy or backup purposes, use the command below:
ls *.log | cp $(xargs) /path/another_folder
Copy Recursively:
find /path/log_folder/ -type f -name '*.log' | cp $(xargs) /path/another_folder/
Copy Recursively:
find /path/log_folder/ -type f -name '*.log' | cp $(xargs) /path/another_folder/
If filenames are the same, overwrite prompt is shown. Files will not be overwritten automatically unless "-rf" arguments is included in the command.
To find files older than 5 days and copy or move those files to another folder use command below:
find /var/log/xdata/ -type f -mtime +5 | cp $(xargs) /path_to_folder
find /var/log/xdata/ -type f -mtime +5 | mv $(xargs) /path_to_folder
Before applying any commands to a production environment, test the commands with dummy data and check the output if it is the desired result.
The commands above can be created as a bash script and apply chmod +x Script_name.sh to the file.
Cheers..till next time. hope it helps.
Linux Android App cheat sheet:
https://play.google.com/store/apps/details?id=com.LinuxMobileKit
Free Android Apps:
Click on links below to find out more:
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
https://play.google.com/store/apps/details?id=com.myrosaryapp
http://quickbytesstuff.blogspot.sg/2014/09/how-to-recite-rosary.html
Divine Mercy Chaplet Guide (A Powerful prayer):
https://play.google.com/store/apps/details?id=com.dmercyapp
Educational Android App for Kids:
https://play.google.com/store/apps/details?id=com.xmultiplication
https://play.google.com/store/apps/details?id=com.letsmultiply
Linux Android App cheat sheet:
https://play.google.com/store/apps/details?id=com.LinuxMobileKit
Free Android Apps:
Click on links below to find out more:
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
https://play.google.com/store/apps/details?id=com.myrosaryapp
http://quickbytesstuff.blogspot.sg/2014/09/how-to-recite-rosary.html
Divine Mercy Chaplet Guide (A Powerful prayer):
https://play.google.com/store/apps/details?id=com.dmercyapp
Educational Android App for Kids:
https://play.google.com/store/apps/details?id=com.xmultiplication
https://play.google.com/store/apps/details?id=com.letsmultiply
Comments
Post a Comment