Learn how to use a host of Linux commands in these 2-minute video tutorials from Sandra Henry-Stocker, author of the Unix as a Second Language blog.
In this Linux tip, we’re going to look at the diff3 command. It’s similar to the diff command, but allows you to compare the contents of three text files instead of just two. In addition, the formatting of the output makes it easy to understand how the files are different. In this command, we compare three simple text files: $ diff3 file1 file2 file3 ====3 1:1,3c 2:1,3c Kids, the seven basic food groups are gum, puff pastry, pizza, pesticides, antibiotics, 3:1,3c Kids, the six basic food groups are fruits, vegetables, grains, protein and dairy The ====3 included in the output below means that the third file is different. If all the files were different, this would show just ====. The output then shows the differences between the first two files (which are the same) and the third which has a different third line. Looking at file3, we can see a 4th line. This line didn’t show up in the diff3 output because it’s the same in all three files. The diff3 command only displays differences.
In this Linux tip, we’re going to look at the colordiff command. It displays the differences between two files like the diff command, but adds color whenever the content is different. This first command has no output because the files are the same. $ colordiff file1 file2 Now let’s compare two files with a difference. $ colordiff file1 file3 1,3c1,3 Kids, the seven basic food a groups are gum, puff pastry, pizza, pesticides, antibiotics, --- Kids, the six basic food groups are fruits, vegetables, grains, protein and dairy Notice how the colors highlight the differences between the two files. Here’s the full content of file3 showing the only line the files share (line 4). $ cat file3 Kids, the six basic food groups are fruits, vegetables, grains, protein and dairy and milk duds!!
In this Linux tip, we’re going to look at the cmp command. It’s a command that allows you to compare the content of two text files. If the files that you are comparing are identical, there will be no output. Here’s an example: $ cmp file1 file2 $ Here’s a file listing … $ ls -l file1 file2 -rw-r--r--. 1 shs shs 104 Aug 21 16:19 file1 -rw-r--r--. 1 shs shs 104 Sep 7 12:11 file2 If the files are different, you can expect to see output like this that describes where the first difference is located. $ cmp file1 file3 file1 file3 differ: byte 12, line 1 These commands display the content of the files: $ cat file1; echo ===============; cat file3 Kids, the seven basic food groups are gum, puff pastry, pizza, pesticides, antibiotics, and milk duds!! =============== Kids, the six basic food groups are fruits, vegetables, grains, protein and dairy and milk duds!! Notice the 12th character of file1 is an “e” and the 12th character of file2 is an “I”. Closing: That’s your Linux tip for the cmp command. It tells you if files are different and, if so, reports the location of the first difference. If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the InfoWorld channel on YouTube. ---------------------------------- SUBSCRIBE: http://www.youtube.com/subscription_center?add_user=InfoWorld FACEBOOK: https://www.facebook.com/Infoworld/ TWITTER: https://twitter.com/Infoworld WEBSITE: http://www.infoworld.com/
In this Linux tip, we’ll take a look at how you can test whether a string or variable includes some regular expression or substring you want to test for.
In this Linux tip, we’ll look at how you can use the grep command to look for more than one value in a single command. This can be useful when you want to select lines of two forms, but ensure they will appear in the same order as they do in the file. To separate the terms, specify them in a grep command of this form: $ grep 'pattern1\|pattern2' filename Here’s an example: $ grep 'Date:\|total:' July_sales The command will grab each line that contains one of these strings and display them like this: $ grep 'Date:\|total:' July_sales Date: July 6 total: $3,492 Date: July 13 total: $4,321 Date: July 20 total: $6,001 Date: July 27 All other lines will be ignored. Note that additional terms can be added using the same separator (\|) as needed and the strings can contain more than one word. Here’s an example of that: $ grep 'empty saying\|never falter' sayings They never falter. Is that an empty saying? Closing: That’s your Linux tip for the grep command to search for multiple strings in a file. If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the InfoWorld channel on YouTube.
In this Linux tip, we’re going to look at a command that allows you see how many days have passed since the beginning of the Linux epoch – Jan 1, 1970. To begin, we use the command below to display the number of seconds since the epoch began on Jan 1, 1970. This is how Linux stores dates and times. $ date +%s 1719337777 To convert this number from the number of seconds to the number of days, you would do this: $ days=`expr 1719337777 / 60 / 60 / 24` 19899 This divides the number of seconds by the number of seconds per minute, minutes per hour and hours per day. And, if you’re not confident about the result, you can convert it to the number of years and see a number that is easier to confirm. $ expr 19899 / 36554
In this Linux tip, we’re going to take a look at the pv (pipe viewer) command that can provide some reassuring visual feedback when some process you will be running might take a long time to complete. In this simple example, everything will run very quickly, but this kind of output for long-running commands will let you know that the process isn’t “hanging” and that, instead, progress is being made.
In this Linux tip, we look at the stat command. Like the ls command, stat displays important details about a file – like permissions and ownership, but in a much different and surprisingly useful way.
In this Linux tip, we’re going to look at what happens on many Linux systems when someone mistypes “ls” – typing “sl” instead. What you can anticipating seeing (provided the sl command has been installed with one of the commands shown below is a rather entertaining image – a steam locomotive that drives across your screen.
In this Linux tip, we're going to take a look at the shuf command.
In this Linux tip, we’ll take a look at the chmod command for changing permissions on a Linux file.
In this Linux tip, we’ll take a look at the apropos command and how it can help you identify commands that you want to use. The meaning of the word apropos is “fitting and to the point”. When you use this command on the Linux command line, you can expect it to generate a list of commands that fit what you’re asking about.
In this Linux tip, we’re going to examine the shred command – a command that allows you to overwrite the content of a file with randomized data so that it is no longer readable and basically impossible to recover.
In this Linux tip, we’re going to look at directories on Linux – basically folders that are set up to house related files. Whenever you use a command like “ls dirname” for a directory, you will see a list of the files it contains.
In this Linux tip, we’re going to examine some commands for generating reports on who is logging into a Linux server. The data for login activity is stored in the /var/log/wtmp file.
In this Linux tip, we’re going to look at the cal (calendar) command. This command allows you to display a calendar for a month or even for a year. Using a command like this, you display a calendar for the current month with the today highlighted.
In this Linux tip, we’re going to take a quick look at the /etc/shadow file on Linux systems. It contains a lot of useful information pertaining to user accounts – and is a file that can only be viewed or changed with root or sudo access.
In this Linux tip, we’ll look at how you can “source” files on the Linux command line. “Sourcing” means reading the file and running the commands that it contains – even if the file isn’t set up with execute permissions. There are two ways to do this. One involves using the source command as in the command “source myfile”. The second way is to replace the word “source” with a dot as in “. myfile”. The results will be the same.
In this Linux tip, we’re going to look at timestamps used on Linux systems. There are actually three of them and they represent the date and time that the file was last accessed, the time it was last modified and the time it was last changed. Modified and changed may suggest the same thing but “modified” implies content changes and “changed” will capture other changes – like permissions.
In this Linux tip, we take a look at the who command – a command that tells you who is logged into the system. If you’re working on a Linux server, you might see that a number of people are logged in. The who command also tells you where the users are logged in from.
Sponsored Links