For those that want to go further.
IntroductionIn this section I'll introduce a few bonus Linux commands and concepts. These are not essential for using the command line but are useful for those that want to take things a bit further. They will give you a feel for some of the more powerful things that Linux can do. I don't plan to cover each of these in detail. There will just be a brief description and some sample usage. Enough to give you the gist of what it does and how to start tinkering. If you're playing with this stuff then I figure you probably have enough understanding and ability to use this as a starter and figure the rest out for yourself by reading the man pages, experimenting and doing further research on Google. Explore and have fun!
Cron - Task SchedulingCron stands for Command Run ON. It is a mechanism that allows you to tell the system to run certain commands at certain times. So for instance, I could craft a script to check how much space is left on the disk that holds the home directories and send an email to certain people if the free disk space gets below a certain amount. Then I would use cron to get this script to run automatically every hour.
Cron allows a fair bit of control in terms of when commands are scheduled to run. Like most things in Linux, it is managed by way of a text file. The layout of the text file can be a little daunting but once you get the hang of it it's not that bad. There are many websites out there with good references to make it easy as well.
The file that manages cron is called a crontab. Each user may have their own crontab and within it each line represents a schedule for a particular command as follows:
* * * * * command to execute
Where the *'s represent (in order from left to right:
A * in any of those places means every one of those increments.
Some examples:
* * * * * /bin/myscript.sh
Execute myscript.sh every minute.
30 3 * * 4 /bin/myscript.sh
Execute myscript.sh every Thursday at 3:30am.
To view a list of what tasks you currently have scheduled you may run the following command:
crontab -l
To edit your scheduled tasks, run the following command. It will open up in your default text editor which is normally Vim.
crontab -e
XargsXargs is a useful tool to run a particular command for every item in a list. It is kinda hard to explain so a demonstration is probably the easiest way to illustrate it's usage.
Let's say we have a series of images in a directory and they have been named with an uppercase extension. We would like them all to be lowercase instead for consistency.
Let's break it down:
Xargs has plenty more options available to it and plenty of opportunity. You often need a touch of creativity and enough persistence to tweak the command until it works.
FindFind is a great tool for fine grained control over searching for files. Like with xargs, the man page is the best place to discover them all. I will illustrate a basic example below. Here we have a problem with disk space running low so we want to do a search for files over 200mb in the users home directories.
Let's break it down:
Or maybe we are part of a team managing a server. It is behaving odd today yet we know it was working fine up until yesterday. We know that all the config files for the server are in the directory /etc so we suspect someone may have changed one of those. Let's do a search to find all files in that directory modified in the last 24 hours.
Tar stands for Tape ARchive and is a popular means for combining and compressing several files into a single file. It was originally created for making backups on tape but is still commonly used today. Even though there are other options such as ZIP files for compression, tar remains popular as it is able to store filesystem information as well such as user and group permissions and dates.
Below I will present the basic forms I typically use for creating and extracting tar archive. Tar has many options however so it's worth a quick skim through the man page.
Let's break it down:
Awk is a good program to use if you need to work with data that is organised into records with fields (such as the sample data below). It allows you to filter the data and control how it is displayed. If you're wondering about the name, it actually comes from the Initials of the 3 authors of the program.
Like find and xargs, it is very powerful but for most people it is very useful with just a brief understanding. If you need to do more complex data mangling, awk can do it but a popular alternative to look into is Perl.
So let's say we wanted to print out only the 2nd column.
Let's break it down:
Now let's say we want to print the order but only if the order is above 10. We also wish to reformat the output a little.
Let's break it down:
Scp is a quick, easy and secure way to copy files between different machines. It is part of the SSH (Secure SHell) suite of tools. With it you may copy files to and from your local machine and a remote machine.
To copy a local file to a remote machine:
Let's break it down:
And the other way around:
It is possible to copy several files in one go using wildcards. If wildcards are not practical then using Tar (above) to compress several files into a single file is also a good approach.
There are other tools available for copying files between machine such as FTP. These are often much more powerful than scp but as a result are more complex to use. If you just want to copy a small number of files then scp is probably the easiest way to go.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4