Linux Training Session Notes, March 2020

Discussion in progress

Background Information

As mentioned in the training session, I am providing the output from the terminal from the commands that were ran and some detail about the output and commentary for each.

Input and Output

The commands entered into the terminal look like the following

almostengr@linuxtraining:~$ input command

and the output from running the command look like the following

I'm some output

Raw Log File

The entire unmodified log file is available for download. Some of the inputs, due to typos, are difficult to read due to the way that PuTTY generates the log files.

CSV Data Files

CSV data files were generated using generatedata.com.

Next Training Session

Future training sessions have not been scheduled at this time. If you are interested in attending a future session, you can reach out to me via the contact page to let me know that you are interested. Once the next session has been scheduled, a notification will be sent out with the details. In addition, sessions will be listed on this website when they are scheduled.

Let The Session Begin

Session in progress

To ensure that everyone was able to see my screen, I ran the top command as it periodically refreshes the data on the screen. Once we had screen sharing going, the training got started.

Whats Running On The System

The top command shows the current CPU usage as well as the processes that are currently running, memory usage, and system up-time. This is similar to the Task Manager in Windows.

To exit this program, you will need to press the "q" key.

almostengr@linuxtraining:~$ top
top - 21:41:08 up 23:48,  1 user,  load average: 0.00, 0.00, 0.00
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
 3528 almost+  20   0   42652   3944   3388 R  0.7  0.4   0:00.63 top
    1 root      20   0  159772   8892   6612 S  0.0  0.9   0:01.95 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd
    4 root       0 -20       0      0      0 I  0.0  0.0   0:00.00 kworker/0:0H
    6 root       0 -20       0      0      0 I  0.0  0.0   0:00.00 mm_percpu_wq
    7 root      20   0       0      0      0 S  0.0  0.0   0:00.31 ksoftirqd/0
    8 root      20   0       0      0      0 I  0.0  0.0   0:07.06 rcu_sched
    9 root      20   0       0      0      0 I  0.0  0.0   0:00.00 rcu_bh
   10 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
   11 root      rt   0       0      0      0 S  0.0  0.0   0:00.32 watchdog/0
   12 root      20   0       0      0      0 S  0.0  0.0   0:00.00 cpuhp/0
   13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   14 root       0 -20       0      0      0 I  0.0  0.0   0:00.00 netns
   15 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_tasks_kthre
   16 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kauditd
   17 root      20   0       0      0      0 S  0.0  0.0   0:00.02 khungtaskd
   18 root      20   0       0      0      0 S  0.0  0.0   0:00.00 oom_reaper
   19 root       0 -20       0      0      0 I  0.0  0.0   0:00.00 writeback
   20 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kcompactd0

Showing What Version of Linux is Running and System Information

almostengr@linuxtraining:~$ uname -a
Linux linuxtraining 4.15.0-88-generic #88-Ubuntu SMP Tue Feb 11 20:11:34 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Printing The Current Directory and Changing Directories

See (print) the current working directory.

almostengr@linuxtraining:~$ pwd
/home/almostengr

List the files in the current directory

almostengr@linuxtraining:~$ ls
almostengr.txt  data2.csv  data.csv  dirtocopy  kenny.txt

Change to the /var/tmp directory. This command has no output unless directory entered does not exist.

almostengr@linuxtraining:~$ cd /var/tmp

Confirm that you are in the /var/tmp directory by printing the current directory

almostengr@linuxtraining:/var/tmp$ pwd
/var/tmp

Go back to the home directory. This command has no output.

almostengr@linuxtraining:/var/tmp$ cd

Confirm that you are in the home directory.

almostengr@linuxtraining:~$ pwd
/home/almostengr

Multiple Ways to Change Directories

This shows that there is more than one way to get to the /var/log directory.

almostengr@linuxtraining:~$ cd ../../var/log
almostengr@linuxtraining:/var/log$ pwd
/var/log

Go back to the home directory.

almostengr@linuxtraining:/var/log$ cd

Navigate to the /var/log directory again, by entering in a different path.

almostengr@linuxtraining:~$ cd /var/log
almostengr@linuxtraining:/var/log$ pwd
/var/log

Listing Directory Contents

List the visible files in the current directory.

almostengr@linuxtraining:~$ ls
almostengr.txt  data2.csv  data.csv  dirtocopy  kenny.txt

List all (hidden and visible) files in the current directory. Hidden files and directories start with a period ..

almostengr@linuxtraining:~$ ls -a
.               .bash_history  .cache     dirtocopy  .profile                   .viminfo
..              .bash_logout   data2.csv  .gnupg     .sudo_as_admin_successful
almostengr.txt  .bashrc        data.csv   kenny.txt  .vim

List all of the files in the current directory with their details.

almostengr@linuxtraining:~$ ls -al
total 72
drwxr-xr-x 6 almostengr almostengr 4096 Mar  1 05:40 .
drwxr-xr-x 3 root       root       4096 Feb 23 21:05 ..
-rw-rw-r-- 1 almostengr almostengr  790 Feb 24 03:11 almostengr.txt
-rw------- 1 almostengr almostengr 2340 Mar  1 17:32 .bash_history
-rw-r--r-- 1 almostengr almostengr  220 Apr  4  2018 .bash_logout
-rw-r--r-- 1 almostengr almostengr 3771 Apr  4  2018 .bashrc
drwx------ 2 almostengr almostengr 4096 Feb 23 21:05 .cache
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 data2.csv
-rw-rw-r-- 1 almostengr almostengr 6538 Mar  1 05:39 data.csv
drwxrwxr-x 2 almostengr almostengr 4096 Feb 24 03:17 dirtocopy
drwx------ 3 almostengr almostengr 4096 Feb 23 21:05 .gnupg
-rw-rw-r-- 1 almostengr almostengr  576 Feb 24 03:11 kenny.txt
-rw-r--r-- 1 almostengr almostengr  807 Apr  4  2018 .profile
-rw-r--r-- 1 almostengr almostengr    0 Feb 23 21:06 .sudo_as_admin_successful
drwxr-xr-x 2 almostengr almostengr 4096 Mar  1 05:39 .vim
-rw------- 1 almostengr almostengr 6805 Mar  1 05:40 .viminfo

One period . refers to the current directory. Thus the command below will change the directory to the current directory.

almostengr@linuxtraining:~$ cd .
almostengr@linuxtraining:~$ pwd
/home/almostengr

Two periods .. refers to the parent directory. Thus the command below will change to the parent directory of the current directory.

almostengr@linuxtraining:~$ cd ..
almostengr@linuxtraining:/home$ pwd
/home

Each user has a home directory. To go back to your home directory, you enter the command below in. This command does not return any output.

almostengr@linuxtraining:/home$ cd

Creating New Folder

To create a new folder, you use the command below. You will need to replace anewfolder with the name of the folder that you want to create. This command does not return any output.

almostengr@linuxtraining:~$ mkdir nanewfolder

Once you have ran the command above, you can use the ls command to confirm that the folder has been created.

almostengr@linuxtraining:~$ ls
almostengr.txt  anewfolder  data2.csv  data.csv  dirtocopy  kenny.txt

Predefined Aliases

On some systems, the directories are highlighted a different color from the files. Ubuntu is one of the systems that does this out of the box. The reason is because there is an alias defined for the ls command. I showed what was really running when performing the ls by showing the alias.

almostengr@linuxtraining:~$ alias ls
alias ls='ls --color=auto'

Removing Folders and Files

If you attempt to remove a directory without specifying the recursive option, the system will complain that the action cannot be done. The system will not allow you to delete a folder without deleting the child elements in that folder because that would leave the child elements orphaned on the system.

almostengr@linuxtraining:~$ rm anewfolder/
rm: cannot remove 'anewfolder/': Is a directory
almostengr@linuxtraining:~$ ls
almostengr.txt  anewfolder  data2.csv  data.csv  dirtocopy  kenny.txt

The recursive option still must be used even if the directory is empty. This time the remove command is run with the recursive option and the folder is removed. The rm command does not return any output unless there is an error executing the command.

almostengr@linuxtraining:~$ rm -r anewfolder/
almostengr@linuxtraining:~$ ls
almostengr.txt  data2.csv  data.csv  dirtocopy  kenny.txt

Below are examples of commands that you do not want to run. If you do run any of the commands, they will result in the entire file system being deleted. Some of these require that the executing user have sudo permissions. The commands in the example below have been commented out so that they cannot be intentionally run.

almostengr@linuxtraining:~$ # do not run
almostengr@linuxtraining:~$ # rm -r /*
almostengr@linuxtraining:~$ # rm -rf /*

The equivalent of the above commands is going to the root / directory and running the commands below. The commands in the example have intentionally been commented out so that they cannot be easily run.

almostengr@linuxtraining:~$ cd /
almostengr@linuxtraining:/$ ls
almostengr@linuxtraining:~$ # do not run
almostengr@linuxtraining:/$ # rm -r f
almostengr@linuxtraining:/$ # rm -r f f *

To find all of the options an example of the rm command, you can enter in the the help argument to the command. The help page wil display different output depending on the distrubution of Linux that you are using.

almostengr@linuxtraining:/$ rm --help

For more information about the command, you can use the man page. The output from this will vary depending on the Linux distribution that you are using.

almostengr@linuxtraining:/$ man rm

Autocomplete can be used with the rm command as well. Just type part of the file name and double press the Tab key to have the system type the rest of the file or to present you with files that match the pattern.

almostengr@linuxtraining:~$ rm cop
copiedfile.csv     copyofsample2.txt  copyofsample.txt
almostengr@linuxtraining:~$ rm copyofsample*
copyofsample2.txt  copyofsample.txt

Below, I show that "sample" as the pattern matched two files. However, "se*" matches three files. Using this wildcard pattern can result in you deleting files that you do not want to delete.

almostengr@linuxtraining:~$ ls *s*e*
almostengr.txt  copyofsample2.txt  copyofsample.txt

If you are not sure what all files will match a pattern, run the pattern of your choice with the ls command first before running the rm command.

Recovering Deleted Files

Recovering delete files on Linux is not an easy task unless you use a disk recovery utility. On Windows-based systems, when a file is deleted, it goes to the Recycle Bin. Linux has no concept of the Recycle Bin. There is a way that the Recycle Bin concept can be done.

To set up your makeshift Recycle Bin on Linux, you can create an alias for the rm command or use a different alias that will move the file to a different directory instead of deleting the file.

alias rm="mv $@ /var/tmp"

If you use the command above as an alias, any time that you use the rm command, it will move the file to the /var/tmp directory instead. Periodically, you will need to "empty the trash" by removing the files from the /var/tmp directory.

Clear The Screen

Clearing the screen will do what it says. The prompt will be moved to the top of the screen. On some systems, this will limit whether you can scroll back or not.

almostengr@linuxtraining:~$ clear

Copying Files

To display the help information for using the file copy, use the --help option. The help page will vary based on the Linux distribution that you are using.

almostengr@linuxtraining:~$ cp --help

This is the list of directory contents before performing a file copy.

almostengr@linuxtraining:~$ ls
almostengr.txt  data2.csv  data.csv  dirtocopy  kenny.txt

If you do not remember the filename that you want to copy or the filename is long that you do not want to type it, then you can use auto-complete to have the system complete the filename for you. Start by typing part of the file name in the prompt.

almostengr@linuxtraining:~$ cp -p d

Then double press the Tab key and you will get the following.

data2.csv  data.csv   dirtocopy/

Since there are multiple matches for files that start with "d", the system will not automatically guess which one that you are trying to type. Instead it will list all of the files that match the criteria that you have defined so that you can pick which one.

The same will happen now that we have typed "data" in the prompt as there are two files that being with "data" in this directory. From here we can type an additional character that matches the file that we want to use in our command and it will complete the rest of the filename.

almostengr@linuxtraining:~$ cp -p data
data2.csv  data.csv

"data2.csv" is the file that is being copied to "copiedfile.csv". To confirm that the file has been copied, we run the ls command with the file names that were used in the cp command as arguments to only show those two files.

almostengr@linuxtraining:~$ cp -p data2.csv copiedfile.csv
almostengr@linuxtraining:~$ ls -al data2.csv copiedfile.csv

Since we used the -p option in our file copy, the original and copied file will have the same last modified date and time.

-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 copiedfile.csv
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 data2.csv

Going to copy the file that we created to another file. This time without using the preserve option. Also going to use the wild card with the ls command to show both files instead of specifying each file name.

almostengr@linuxtraining:~$ cp sample.txt copysofsample.txt
almostengr@linuxtraining:~$ ls -al *sample*
-rw-rw-r-- 1 almostengr almostengr 0 Mar  1 22:15 copyofsample.txt
-rw-rw-r-- 1 almostengr almostengr 0 Mar  1 22:12 sample.txt

Since the -p option was not used when copying the file, the copied file will have the current timestamp (22:15).

Creating Files

To create a file, you can use the touch command. The file will be created with the name that you provide.

almostengr@linuxtraining:~$ touch sample.txt
almostengr@linuxtraining:~$ ls -al sample.txt
-rw-rw-r-- 1 almostengr almostengr 0 Mar  1 22:12 sample.txt

Viewing File Contents

There are many ways of viewing file contents. To display an entire file on the screen, you use cat.

almostengr@linuxtraining:~$ cat data2.csv
id,first_name,last_name,email,region,country
1,Christian,Walls,non.hendrerit.id@a.net,Manitoba,Spain
2,Mona,Morales,pulvinar.arcu.et@lacusEtiam.ca,Cusco,Mongolia
3,Channing,Ford,ipsum.dolor.sit@id.ca,Metropolitana de Santiago,Faroe Islands
4,Aurora,Lucas,dis.parturient.montes@Proin.net,Waals-Brabant,Montserrat
5,John,Hunter,Cras.eu.tellus@Integerurna.ca,Andhra Pradesh,Sierra Leone
6,Abdul,Shepherd,sed@vestibulumnequesed.com,ATL,Dominican Republic
7,Whilemina,Washington,consectetuer.adipiscing.elit@dolor.net,AQ,Syria
8,Chantale,Rivas,non.vestibulum@Cras.co.uk,SL,Moldova
9,Marcia,Quinn,ante@risus.org,Loreto,Malawi
10,Alexander,Alvarado,vulputate@ametfaucibusut.net,QC,Hong Kong
11,Odessa,Phelps,ac.mi.eleifend@mus.com,Antioquia,Liechtenstein
12,Hammett,Rowe,tincidunt.aliquam.arcu@Donecegestas.co.uk,SJ,Malta
13,Kasimir,Bentley,pellentesque.massa.lobortis@Integeraliquam.ca,East Kalimantan,Fiji
14,Macon,Stone,varius.ultrices.mauris@ornarelectusjusto.com,JT,Macao
15,Abdul,Dejesus,eget@ridiculus.co.uk,Hamburg,Israel
16,Raphael,Harrington,mattis.Cras@est.co.uk,Irkutsk Oblast,Mauritania
17,Thane,Williams,diam.vel.arcu@aptenttaciti.ca,NGR,Heard Island and Mcdonald Islands
18,Lucian,Sexton,ipsum.Suspendisse.sagittis@velconvallis.ca,Assam,Fiji
19,Destiny,Hampton,ligula.elit.pretium@a.edu,BC,Wallis and Futuna
20,Anjolie,Bates,id.mollis.nec@semper.ca,NSW,Cape Verde
21,Adena,Dickson,Quisque@estMauriseu.net,MO,Macao
22,Cassandra,Cherry,nec@diamnuncullamcorper.com,MP,Botswana
23,Nigel,Holden,et@varius.co.uk,IV,"Saint Helena, Ascension and Tristan da Cunha"
24,Sylvester,Thornton,Cras@utnullaCras.co.uk,QC,Mexico
25,Dante,Kelly,blandit.at@fermentum.com,FATA,French Guiana
26,Mercedes,Oneal,Nullam@vehicula.net,Metropolitana de Santiago,Cyprus
27,Vielka,Shields,Quisque.ac.libero@leo.com,East Nusa Tenggara,Togo
28,Nasim,Sharp,id.erat.Etiam@nascetur.org,F,Reunion
29,Eric,Sosa,tellus.faucibus.leo@Aliquamfringilla.net,Mic,South Africa
30,Nigel,Mills,a.tortor@metuseu.org,Andaluca,Haiti
31,Armand,Fisher,Donec.porttitor.tellus@diamvel.co.uk,Delaware,Bhutan
32,Noel,Dennis,pharetra.felis@Vestibulumante.net,Gl,Guyana
33,Hanna,Moore,velit.eget.laoreet@utnisia.edu,SB,Burkina Faso
34,Courtney,White,lectus.quis@enimSednulla.org,CO,Cambodia
35,Cameron,Larson,cubilia@fermentumrisus.edu,ON,Nepal
36,Wallace,Wiggins,at@nonleo.ca,AN,Indonesia
37,Winter,Tanner,Nam.ligula@orcitinciduntadipiscing.ca,NE,Kazakhstan
38,Caleb,Rodriguez,Etiam.laoreet@egestas.edu,West Java,Bangladesh
39,Dorian,Simpson,mi.eleifend@tinciduntpede.edu,West Java,Mayotte
40,Breanna,Burton,elit@nunc.com,TYU,Indonesia
41,Quentin,Joyce,augue@Aeneangravidanunc.org,So Paulo,Taiwan
42,Hayes,Meyers,arcu.iaculis@felis.org,Bolvar,Puerto Rico
43,Zeph,Hull,Nunc.quis.arcu@magnisdisparturient.co.uk,Zl,Palau
44,Igor,Becker,arcu.Nunc.mauris@justositamet.com,ON,Romania
45,Nayda,Bernard,sodales@eunequepellentesque.org,Berlin,Saudi Arabia
46,Alika,Puckett,Nullam.feugiat@sagittis.edu,Wie,Christmas Island
47,Brett,Browning,feugiat.placerat.velit@consequatnecmollis.co.uk,NL,Argentina
48,Mollie,Chavez,euismod.ac@inlobortis.ca,Volgograd Oblast,Mozambique
49,Marcia,Ramos,Integer.id@luctuset.com,L.,Guatemala
50,Helen,Gardner,pellentesque@DonecnibhQuisque.org,Ayd,Costa Rica
51,Castor,Sharp,sem@a.net,HB,Malawi
52,Pamela,Golden,Aenean.eget.metus@turpisvitae.net,NT,Costa Rica
53,Elvis,Beasley,sem.consequat@nasceturridiculusmus.com,Orkney,Tanzania
54,Hollee,Allen,Donec.consectetuer@loremDonec.com,OG,Saudi Arabia
55,Sonya,Rosario,facilisis.Suspendisse@diamvelarcu.com,Rostov Oblast,Isle of Man
56,Zena,Blair,arcu.Vestibulum.ante@facilisisSuspendisse.edu,KN,Cayman Islands
57,Drew,Rasmussen,non@estNunc.org,Azad Kashmir,Pitcairn Islands
58,Ivan,William,Curabitur.massa.Vestibulum@lectusCum.com,Madhya Pradesh,Madagascar
59,Sheila,King,varius@vestibulumlorem.org,Valparaso,Finland
60,Steel,Rosa,arcu.Sed@ultrices.net,Connacht,South Georgia and The South Sandwich Islands
61,Galvin,Rush,libero.est.congue@et.net,PR,Malawi
62,Peter,Skinner,quis.massa@quamquisdiam.net,GA,France
63,Allegra,Compton,nibh.vulputate.mauris@dapibusid.net,BA,Sierra Leone
64,Harlan,Lawrence,Donec@nonummyipsumnon.org,Minnesota,Nigeria
65,Keaton,Baird,nisi.sem@Cum.ca,West Java,Hungary
66,Kane,Perkins,in.hendrerit.consectetuer@scelerisqueduiSuspendisse.co.uk,HA,Holy See (Vatican City State)
67,Fallon,Valdez,aliquet@nisl.ca,Catalunya,Antigua and Barbuda
68,Ria,Vaughan,odio.sagittis@nibh.ca,Paran,Sierra Leone
69,Colleen,Hull,commodo@atpretium.co.uk,Missouri,Tajikistan
70,Raya,Benjamin,Suspendisse.aliquet@ultriciesornareelit.net,South Jeolla,"Palestine, State of"
71,Ariana,Cross,mus.Aenean@utquam.com,Mazowieckie,Mauritania
72,Brian,Taylor,dis.parturient@rutrumFuscedolor.edu,FATA,El Salvador
73,Tara,Ruiz,Nam.interdum.enim@magnisdis.com,Puno,Rwanda
74,Dacey,Hobbs,nibh@Maecenasiaculis.net,Vienna,Andorra
75,Kennan,Lloyd,ac.turpis.egestas@FuscefeugiatLorem.net,LAL,Uruguay
76,Dana,Coffey,scelerisque.mollis@egetmagnaSuspendisse.net,SI,Sudan
77,Lillith,Maxwell,dictum@tempus.com,V,Guatemala
78,Kirk,Odonnell,ornare.In@feugiatSed.edu,Lombardia,Spain
79,Logan,Pugh,Suspendisse.non.leo@massalobortisultrices.ca,Borno,Micronesia
80,Kay,Francis,porttitor.eros@FuscefeugiatLorem.com,C,Libya
81,Velma,Gaines,sodales.Mauris.blandit@dictum.ca,SJ,Azerbaijan
82,Melvin,Downs,non@adipiscinglobortis.co.uk,Kincardineshire,Faroe Islands
83,Kuame,Shields,tellus.Nunc@eutempor.co.uk,ON,French Polynesia
84,Jerome,Moses,id.nunc.interdum@idante.edu,VIC,Russian Federation
85,Ali,Diaz,dolor@quisaccumsanconvallis.com,C,Syria
86,Isabella,Snider,sollicitudin.adipiscing.ligula@dis.com,Gye,Tanzania
87,Ria,Scott,sem.semper.erat@Uttincidunt.edu,Andaluca,Hungary
88,Courtney,Washington,eu.tellus.eu@Aliquamerat.co.uk,Piura,Mayotte
89,Brendan,Blackwell,nascetur.ridiculus.mus@velarcu.org,Sokoto,United Arab Emirates
90,Elizabeth,Moreno,Morbi@accumsan.edu,SH,Cocos (Keeling) Islands
91,Mariam,Ferrell,sem@Donecconsectetuermauris.ca,LAL,Mozambique
92,Geoffrey,Harmon,dui@Loremipsum.co.uk,GA,Thailand
93,Kamal,Chambers,orci.adipiscing@purus.ca,Leinster,Croatia
94,Noelani,Witt,libero.Morbi.accumsan@ametfaucibus.net,LAM,Micronesia
95,Jason,Mack,tellus.id.nunc@pedeSuspendissedui.co.uk,Leinster,Sao Tome and Principe
96,Eugenia,Cardenas,Duis@nequeNullam.edu,PIU,France
97,Judith,Guerrero,facilisis.Suspendisse@Sedmalesuada.edu,Metropolitana de Santiago,Tunisia
98,Branden,Leon,sed.leo@liberoIntegerin.com,La Libertad,French Guiana
99,Tucker,Clark,nibh.sit.amet@leoVivamus.net,Emilia-Romagna,Saint Kitts and Nevis
100,Todd,Dyer,nunc.nulla.vulputate@hendrerit.co.uk,Gl,Mozambique

A better way of displaying data on the page, is to use the more command. This will display one full screen of information. To navigate using the more command, you can

  • go the next screen of information by using the space bar
  • go forward one line by pressing the Enter key
  • go backwards one line by pressing the "B" key
  • go back to the command prompt by pressing the "Q" key or continue to end the space bar until you reach the end of the file
almostengr@linuxtraining:~$ more data2.csv
id,first_name,last_name,email,region,country
1,Christian,Walls,non.hendrerit.id@a.net,Manitoba,Spain
2,Mona,Morales,pulvinar.arcu.et@lacusEtiam.ca,Cusco,Mongolia
3,Channing,Ford,ipsum.dolor.sit@id.ca,Metropolitana de Santiago,Faroe Islands
4,Aurora,Lucas,dis.parturient.montes@Proin.net,Waals-Brabant,Montserrat
5,John,Hunter,Cras.eu.tellus@Integerurna.ca,Andhra Pradesh,Sierra Leone
6,Abdul,Shepherd,sed@vestibulumnequesed.com,ATL,Dominican Republic
7,Whilemina,Washington,consectetuer.adipiscing.elit@dolor.net,AQ,Syria
8,Chantale,Rivas,non.vestibulum@Cras.co.uk,SL,Moldova
9,Marcia,Quinn,ante@risus.org,Loreto,Malawi
10,Alexander,Alvarado,vulputate@ametfaucibusut.net,QC,Hong Kong
11,Odessa,Phelps,ac.mi.eleifend@mus.com,Antioquia,Liechtenstein
12,Hammett,Rowe,tincidunt.aliquam.arcu@Donecegestas.co.uk,SJ,Malta
13,Kasimir,Bentley,pellentesque.massa.lobortis@Integeraliquam.ca,East Kalimantan,Fiji
14,Macon,Stone,varius.ultrices.mauris@ornarelectusjusto.com,JT,Macao
15,Abdul,Dejesus,eget@ridiculus.co.uk,Hamburg,Israel
16,Raphael,Harrington,mattis.Cras@est.co.uk,Irkutsk Oblast,Mauritania
17,Thane,Williams,diam.vel.arcu@aptenttaciti.ca,NGR,Heard Island and Mcdonald Islands
18,Lucian,Sexton,ipsum.Suspendisse.sagittis@velconvallis.ca,Assam,Fiji
19,Destiny,Hampton,ligula.elit.pretium@a.edu,BC,Wallis and Futuna
20,Anjolie,Bates,id.mollis.nec@semper.ca,NSW,Cape Verde
21,Adena,Dickson,Quisque@estMauriseu.net,MO,Macao
22,Cassandra,Cherry,nec@diamnuncullamcorper.com,MP,Botswana
23,Nigel,Holden,et@varius.co.uk,IV,"Saint Helena, Ascension and Tristan da Cunha"
24,Sylvester,Thornton,Cras@utnullaCras.co.uk,QC,Mexico
--More--(24%)
25,Dante,Kelly,blandit.at@fermentum.com,FATA,French Guiana
--More--(25%)
26,Mercedes,Oneal,Nullam@vehicula.net,Metropolitana de Santiago,Cyprus
--More--(26%)

"B" key was pressed which resulted in this message being shown in the bottom left of the screen and the file backing up.

...back 1 page

I used the space bar to go forward which shows the next set of rows on the screen.

25,Dante,Kelly,blandit.at@fermentum.com,FATA,French Guiana
26,Mercedes,Oneal,Nullam@vehicula.net,Metropolitana de Santiago,Cyprus
27,Vielka,Shields,Quisque.ac.libero@leo.com,East Nusa Tenggara,Togo
28,Nasim,Sharp,id.erat.Etiam@nascetur.org,F,Reunion
29,Eric,Sosa,tellus.faucibus.leo@Aliquamfringilla.net,Mic,South Africa
30,Nigel,Mills,a.tortor@metuseu.org,Andaluca,Haiti
31,Armand,Fisher,Donec.porttitor.tellus@diamvel.co.uk,Delaware,Bhutan
32,Noel,Dennis,pharetra.felis@Vestibulumante.net,Gl,Guyana
33,Hanna,Moore,velit.eget.laoreet@utnisia.edu,SB,Burkina Faso
34,Courtney,White,lectus.quis@enimSednulla.org,CO,Cambodia
35,Cameron,Larson,cubilia@fermentumrisus.edu,ON,Nepal
36,Wallace,Wiggins,at@nonleo.ca,AN,Indonesia
37,Winter,Tanner,Nam.ligula@orcitinciduntadipiscing.ca,NE,Kazakhstan
38,Caleb,Rodriguez,Etiam.laoreet@egestas.edu,West Java,Bangladesh
39,Dorian,Simpson,mi.eleifend@tinciduntpede.edu,West Java,Mayotte
40,Breanna,Burton,elit@nunc.com,TYU,Indonesia
41,Quentin,Joyce,augue@Aeneangravidanunc.org,So Paulo,Taiwan
42,Hayes,Meyers,arcu.iaculis@felis.org,Bolvar,Puerto Rico
43,Zeph,Hull,Nunc.quis.arcu@magnisdisparturient.co.uk,Zl,Palau
44,Igor,Becker,arcu.Nunc.mauris@justositamet.com,ON,Romania
45,Nayda,Bernard,sodales@eunequepellentesque.org,Berlin,Saudi Arabia
46,Alika,Puckett,Nullam.feugiat@sagittis.edu,Wie,Christmas Island
47,Brett,Browning,feugiat.placerat.velit@consequatnecmollis.co.uk,NL,Argentina
48,Mollie,Chavez,euismod.ac@inlobortis.ca,Volgograd Oblast,Mozambique
49,Marcia,Ramos,Integer.id@luctuset.com,L.,Guatemala
50,Helen,Gardner,pellentesque@DonecnibhQuisque.org,Ayd,Costa Rica
--More--(52%)

The more command can be used for other operations, including paging the output for files and directories.

We navigated to the /etc directory and listed the contents.

almostengr@linuxtraining:~$ cd /etc/
almostengr@linuxtraining:/etc$ ls
acpi                    groff            manpath.config           rmt
adduser.conf            group            mdadm                    rpc
alternatives            group-           mime.types               rsyslog.conf
apm                     grub.d           mke2fs.conf              rsyslog.d
apparmor                gshadow          modprobe.d               screenrc
apparmor.d              gshadow-         modules                  securetty
apport                  gss              modules-load.d           security
apt                     hdparm.conf      monit                    selinux
at.deny                 host.conf        mtab                     services
bash.bashrc             hostname         nanorc                   shadow
bash_completion         hosts            netplan                  shadow-
bash_completion.d       hosts.allow      network                  shells
bindresvport.blacklist  hosts.deny       networkd-dispatcher      skel
binfmt.d                init.d           NetworkManager           sos.conf
byobu                   initramfs-tools  networks                 ssh
ca-certificates         inputrc          newt                     ssl
ca-certificates.conf    iproute2         nsswitch.conf            subgid
calendar                iscsi            opt                      subgid-
cloud                   issue            os-release               subuid
console-setup           issue.net        overlayroot.conf         subuid-
cron.d                  kernel           pam.conf                 sudoers
cron.daily              kernel-img.conf  pam.d                    sudoers.d
cron.hourly             landscape        passwd                   sysctl.conf
cron.monthly            ldap             passwd-                  sysctl.d
crontab                 ld.so.cache      perl                     systemd
cron.weekly             ld.so.conf       pm                       terminfo
cryptsetup-initramfs    ld.so.conf.d     polkit-1                 thermald
crypttab                legal            pollinate                timezone
dbus-1                  libaudit.conf    popularity-contest.conf  tmpfiles.d
debconf.conf            libnl-3          profile                  ucf.conf
debian_version          locale.alias     profile.d                udev
default                 locale.gen       protocols                ufw
deluser.conf            localtime        python                   updatedb.conf
depmod.d                logcheck         python2.7                update-manager
dhcp                    login.defs       python3                  update-motd.d
dnsmasq.d               logrotate.conf   python3.6                update-notifier
dnsmasq.d-available     logrotate.d      rc0.d                    vim
dpkg                    lsb-release      rc1.d                    vmware-tools
environment             ltrace.conf      rc2.d                    vtrgb
ethertypes              lvm              rc3.d                    wgetrc
fail2ban                machine-id       rc4.d                    X11
fonts                   magic            rc5.d                    xdg
fstab                   magic.mime       rc6.d                    zsh_command_not_found
fuse.conf               mailcap          rcS.d
gai.conf                mailcap.order    resolv.conf

Question was asked if more could only be used on data files. I showed that it could be used on any text file on the system. I also mentioned that it could be used on image files, but that the output would not be pretty.

almostengr@linuxtraining:/etc$ more libaudit.conf
## This is the configuration file for libaudit tunables.
## It is currently only used for the failure_action tunable.

## failure_action can be: log, ignore, terminate
failure_action = ignore

Viewing Files (From Beginning of File) Using Head

The head command is used to read from the top of a file. To find out the options for this command, you can run the command below.

almostengr@linuxtraining:~$ head --help

By default, head will display the top 10 lines in a file. You can specify the number of lines that it should display. In the command below, I have specified that it display the top 15 lines of the file.

almostengr@linuxtraining:~$ head -15 data2.csv
id,first_name,last_name,email,region,country
1,Christian,Walls,non.hendrerit.id@a.net,Manitoba,Spain
2,Mona,Morales,pulvinar.arcu.et@lacusEtiam.ca,Cusco,Mongolia
3,Channing,Ford,ipsum.dolor.sit@id.ca,Metropolitana de Santiago,Faroe Islands
4,Aurora,Lucas,dis.parturient.montes@Proin.net,Waals-Brabant,Montserrat
5,John,Hunter,Cras.eu.tellus@Integerurna.ca,Andhra Pradesh,Sierra Leone
6,Abdul,Shepherd,sed@vestibulumnequesed.com,ATL,Dominican Republic
7,Whilemina,Washington,consectetuer.adipiscing.elit@dolor.net,AQ,Syria
8,Chantale,Rivas,non.vestibulum@Cras.co.uk,SL,Moldova
9,Marcia,Quinn,ante@risus.org,Loreto,Malawi
10,Alexander,Alvarado,vulputate@ametfaucibusut.net,QC,Hong Kong
11,Odessa,Phelps,ac.mi.eleifend@mus.com,Antioquia,Liechtenstein
12,Hammett,Rowe,tincidunt.aliquam.arcu@Donecegestas.co.uk,SJ,Malta
13,Kasimir,Bentley,pellentesque.massa.lobortis@Integeraliquam.ca,East Kalimantan,Fiji
14,Macon,Stone,varius.ultrices.mauris@ornarelectusjusto.com,JT,Macao

If you specify that it display more lines than what are in the file, it will be the equivalent of running the cat command as it will display the entire file. The data2.csv file only has 101 lines in it. Since 125 was specified as the number of lines to print out, it will display the entire file.

almostengr@linuxtraining:~$ head -125 data2.csv
id,first_name,last_name,email,region,country
1,Christian,Walls,non.hendrerit.id@a.net,Manitoba,Spain
2,Mona,Morales,pulvinar.arcu.et@lacusEtiam.ca,Cusco,Mongolia
3,Channing,Ford,ipsum.dolor.sit@id.ca,Metropolitana de Santiago,Faroe Islands
4,Aurora,Lucas,dis.parturient.montes@Proin.net,Waals-Brabant,Montserrat
5,John,Hunter,Cras.eu.tellus@Integerurna.ca,Andhra Pradesh,Sierra Leone
6,Abdul,Shepherd,sed@vestibulumnequesed.com,ATL,Dominican Republic
7,Whilemina,Washington,consectetuer.adipiscing.elit@dolor.net,AQ,Syria
8,Chantale,Rivas,non.vestibulum@Cras.co.uk,SL,Moldova
9,Marcia,Quinn,ante@risus.org,Loreto,Malawi
10,Alexander,Alvarado,vulputate@ametfaucibusut.net,QC,Hong Kong
11,Odessa,Phelps,ac.mi.eleifend@mus.com,Antioquia,Liechtenstein
12,Hammett,Rowe,tincidunt.aliquam.arcu@Donecegestas.co.uk,SJ,Malta
13,Kasimir,Bentley,pellentesque.massa.lobortis@Integeraliquam.ca,East Kalimantan,Fiji
14,Macon,Stone,varius.ultrices.mauris@ornarelectusjusto.com,JT,Macao
15,Abdul,Dejesus,eget@ridiculus.co.uk,Hamburg,Israel
16,Raphael,Harrington,mattis.Cras@est.co.uk,Irkutsk Oblast,Mauritania
17,Thane,Williams,diam.vel.arcu@aptenttaciti.ca,NGR,Heard Island and Mcdonald Islands
18,Lucian,Sexton,ipsum.Suspendisse.sagittis@velconvallis.ca,Assam,Fiji
19,Destiny,Hampton,ligula.elit.pretium@a.edu,BC,Wallis and Futuna
20,Anjolie,Bates,id.mollis.nec@semper.ca,NSW,Cape Verde
21,Adena,Dickson,Quisque@estMauriseu.net,MO,Macao
22,Cassandra,Cherry,nec@diamnuncullamcorper.com,MP,Botswana
23,Nigel,Holden,et@varius.co.uk,IV,"Saint Helena, Ascension and Tristan da Cunha"
24,Sylvester,Thornton,Cras@utnullaCras.co.uk,QC,Mexico
25,Dante,Kelly,blandit.at@fermentum.com,FATA,French Guiana
26,Mercedes,Oneal,Nullam@vehicula.net,Metropolitana de Santiago,Cyprus
27,Vielka,Shields,Quisque.ac.libero@leo.com,East Nusa Tenggara,Togo
28,Nasim,Sharp,id.erat.Etiam@nascetur.org,F,Reunion
29,Eric,Sosa,tellus.faucibus.leo@Aliquamfringilla.net,Mic,South Africa
30,Nigel,Mills,a.tortor@metuseu.org,Andaluca,Haiti
31,Armand,Fisher,Donec.porttitor.tellus@diamvel.co.uk,Delaware,Bhutan
32,Noel,Dennis,pharetra.felis@Vestibulumante.net,Gl,Guyana
33,Hanna,Moore,velit.eget.laoreet@utnisia.edu,SB,Burkina Faso
34,Courtney,White,lectus.quis@enimSednulla.org,CO,Cambodia
35,Cameron,Larson,cubilia@fermentumrisus.edu,ON,Nepal
36,Wallace,Wiggins,at@nonleo.ca,AN,Indonesia
37,Winter,Tanner,Nam.ligula@orcitinciduntadipiscing.ca,NE,Kazakhstan
38,Caleb,Rodriguez,Etiam.laoreet@egestas.edu,West Java,Bangladesh
39,Dorian,Simpson,mi.eleifend@tinciduntpede.edu,West Java,Mayotte
40,Breanna,Burton,elit@nunc.com,TYU,Indonesia
41,Quentin,Joyce,augue@Aeneangravidanunc.org,So Paulo,Taiwan
42,Hayes,Meyers,arcu.iaculis@felis.org,Bolvar,Puerto Rico
43,Zeph,Hull,Nunc.quis.arcu@magnisdisparturient.co.uk,Zl,Palau
44,Igor,Becker,arcu.Nunc.mauris@justositamet.com,ON,Romania
45,Nayda,Bernard,sodales@eunequepellentesque.org,Berlin,Saudi Arabia
46,Alika,Puckett,Nullam.feugiat@sagittis.edu,Wie,Christmas Island
47,Brett,Browning,feugiat.placerat.velit@consequatnecmollis.co.uk,NL,Argentina
48,Mollie,Chavez,euismod.ac@inlobortis.ca,Volgograd Oblast,Mozambique
49,Marcia,Ramos,Integer.id@luctuset.com,L.,Guatemala
50,Helen,Gardner,pellentesque@DonecnibhQuisque.org,Ayd,Costa Rica
51,Castor,Sharp,sem@a.net,HB,Malawi
52,Pamela,Golden,Aenean.eget.metus@turpisvitae.net,NT,Costa Rica
53,Elvis,Beasley,sem.consequat@nasceturridiculusmus.com,Orkney,Tanzania
54,Hollee,Allen,Donec.consectetuer@loremDonec.com,OG,Saudi Arabia
55,Sonya,Rosario,facilisis.Suspendisse@diamvelarcu.com,Rostov Oblast,Isle of Man
56,Zena,Blair,arcu.Vestibulum.ante@facilisisSuspendisse.edu,KN,Cayman Islands
57,Drew,Rasmussen,non@estNunc.org,Azad Kashmir,Pitcairn Islands
58,Ivan,William,Curabitur.massa.Vestibulum@lectusCum.com,Madhya Pradesh,Madagascar
59,Sheila,King,varius@vestibulumlorem.org,Valparaso,Finland
60,Steel,Rosa,arcu.Sed@ultrices.net,Connacht,South Georgia and The South Sandwich Islands
61,Galvin,Rush,libero.est.congue@et.net,PR,Malawi
62,Peter,Skinner,quis.massa@quamquisdiam.net,GA,France
63,Allegra,Compton,nibh.vulputate.mauris@dapibusid.net,BA,Sierra Leone
64,Harlan,Lawrence,Donec@nonummyipsumnon.org,Minnesota,Nigeria
65,Keaton,Baird,nisi.sem@Cum.ca,West Java,Hungary
66,Kane,Perkins,in.hendrerit.consectetuer@scelerisqueduiSuspendisse.co.uk,HA,Holy See (Vatican City State)
67,Fallon,Valdez,aliquet@nisl.ca,Catalunya,Antigua and Barbuda
68,Ria,Vaughan,odio.sagittis@nibh.ca,Paran,Sierra Leone
69,Colleen,Hull,commodo@atpretium.co.uk,Missouri,Tajikistan
70,Raya,Benjamin,Suspendisse.aliquet@ultriciesornareelit.net,South Jeolla,"Palestine, State of"
71,Ariana,Cross,mus.Aenean@utquam.com,Mazowieckie,Mauritania
72,Brian,Taylor,dis.parturient@rutrumFuscedolor.edu,FATA,El Salvador
73,Tara,Ruiz,Nam.interdum.enim@magnisdis.com,Puno,Rwanda
74,Dacey,Hobbs,nibh@Maecenasiaculis.net,Vienna,Andorra
75,Kennan,Lloyd,ac.turpis.egestas@FuscefeugiatLorem.net,LAL,Uruguay
76,Dana,Coffey,scelerisque.mollis@egetmagnaSuspendisse.net,SI,Sudan
77,Lillith,Maxwell,dictum@tempus.com,V,Guatemala
78,Kirk,Odonnell,ornare.In@feugiatSed.edu,Lombardia,Spain
79,Logan,Pugh,Suspendisse.non.leo@massalobortisultrices.ca,Borno,Micronesia
80,Kay,Francis,porttitor.eros@FuscefeugiatLorem.com,C,Libya
81,Velma,Gaines,sodales.Mauris.blandit@dictum.ca,SJ,Azerbaijan
82,Melvin,Downs,non@adipiscinglobortis.co.uk,Kincardineshire,Faroe Islands
83,Kuame,Shields,tellus.Nunc@eutempor.co.uk,ON,French Polynesia
84,Jerome,Moses,id.nunc.interdum@idante.edu,VIC,Russian Federation
85,Ali,Diaz,dolor@quisaccumsanconvallis.com,C,Syria
86,Isabella,Snider,sollicitudin.adipiscing.ligula@dis.com,Gye,Tanzania
87,Ria,Scott,sem.semper.erat@Uttincidunt.edu,Andaluca,Hungary
88,Courtney,Washington,eu.tellus.eu@Aliquamerat.co.uk,Piura,Mayotte
89,Brendan,Blackwell,nascetur.ridiculus.mus@velarcu.org,Sokoto,United Arab Emirates
90,Elizabeth,Moreno,Morbi@accumsan.edu,SH,Cocos (Keeling) Islands
91,Mariam,Ferrell,sem@Donecconsectetuermauris.ca,LAL,Mozambique
92,Geoffrey,Harmon,dui@Loremipsum.co.uk,GA,Thailand
93,Kamal,Chambers,orci.adipiscing@purus.ca,Leinster,Croatia
94,Noelani,Witt,libero.Morbi.accumsan@ametfaucibus.net,LAM,Micronesia
95,Jason,Mack,tellus.id.nunc@pedeSuspendissedui.co.uk,Leinster,Sao Tome and Principe
96,Eugenia,Cardenas,Duis@nequeNullam.edu,PIU,France
97,Judith,Guerrero,facilisis.Suspendisse@Sedmalesuada.edu,Metropolitana de Santiago,Tunisia
98,Branden,Leon,sed.leo@liberoIntegerin.com,La Libertad,French Guiana
99,Tucker,Clark,nibh.sit.amet@leoVivamus.net,Emilia-Romagna,Saint Kitts and Nevis
100,Todd,Dyer,nunc.nulla.vulputate@hendrerit.co.uk,Gl,Mozambique

Viewing Files (From End of File), Using Tail

tail command works in the same fashion as the head command excepts it reads from the end of the file. By default, it will display the last 10 lines of the file. In the command below, I have specified that it displays the last 15 lines of the file.

almostengr@linuxtraining:~$ tail -15 data2.csv
86,Isabella,Snider,sollicitudin.adipiscing.ligula@dis.com,Gye,Tanzania
87,Ria,Scott,sem.semper.erat@Uttincidunt.edu,Andaluca,Hungary
88,Courtney,Washington,eu.tellus.eu@Aliquamerat.co.uk,Piura,Mayotte
89,Brendan,Blackwell,nascetur.ridiculus.mus@velarcu.org,Sokoto,United Arab Emirates
90,Elizabeth,Moreno,Morbi@accumsan.edu,SH,Cocos (Keeling) Islands
91,Mariam,Ferrell,sem@Donecconsectetuermauris.ca,LAL,Mozambique
92,Geoffrey,Harmon,dui@Loremipsum.co.uk,GA,Thailand
93,Kamal,Chambers,orci.adipiscing@purus.ca,Leinster,Croatia
94,Noelani,Witt,libero.Morbi.accumsan@ametfaucibus.net,LAM,Micronesia
95,Jason,Mack,tellus.id.nunc@pedeSuspendissedui.co.uk,Leinster,Sao Tome and Principe
96,Eugenia,Cardenas,Duis@nequeNullam.edu,PIU,France
97,Judith,Guerrero,facilisis.Suspendisse@Sedmalesuada.edu,Metropolitana de Santiago,Tunisia
98,Branden,Leon,sed.leo@liberoIntegerin.com,La Libertad,French Guiana
99,Tucker,Clark,nibh.sit.amet@leoVivamus.net,Emilia-Romagna,Saint Kitts and Nevis
100,Todd,Dyer,nunc.nulla.vulputate@hendrerit.co.uk,Gl,Mozambique
almostengr@linuxtraining:~$ ls -altr
total 80
-rw-r--r-- 1 almostengr almostengr  807 Apr  4  2018 .profile
-rw-r--r-- 1 almostengr almostengr 3771 Apr  4  2018 .bashrc
-rw-r--r-- 1 almostengr almostengr  220 Apr  4  2018 .bash_logout
drwxr-xr-x 3 root       root       4096 Feb 23 21:05 ..
drwx------ 2 almostengr almostengr 4096 Feb 23 21:05 .cache
drwx------ 3 almostengr almostengr 4096 Feb 23 21:05 .gnupg
-rw-r--r-- 1 almostengr almostengr    0 Feb 23 21:06 .sudo_as_admin_successful
-rw-rw-r-- 1 almostengr almostengr  576 Feb 24 03:11 kenny.txt
-rw-rw-r-- 1 almostengr almostengr  790 Feb 24 03:11 almostengr.txt
drwxrwxr-x 2 almostengr almostengr 4096 Feb 24 03:17 dirtocopy
-rw-rw-r-- 1 almostengr almostengr 6538 Mar  1 05:39 data.csv
drwxr-xr-x 2 almostengr almostengr 4096 Mar  1 05:39 .vim
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 data2.csv
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 copiedfile.csv
-rw------- 1 almostengr almostengr 6805 Mar  1 05:40 .viminfo
-rw------- 1 almostengr almostengr 2340 Mar  1 17:32 .bash_history
-rw-rw-r-- 1 almostengr almostengr    0 Mar  1 22:17 copyofsample.txt
-rw-rw-r-- 1 almostengr almostengr    0 Mar  1 22:17 copyofsample2.txt
drwxr-xr-x 6 almostengr almostengr 4096 Mar  1 22:17 .

Listing Files By Last Modified and Sort Order

To see the list of options that can be used with the ls command, you can use the help option or man page.

almostengr@linuxtraining:~$ ls --help

or

almostengr@linuxtraining:/etc$ man ls

To list files in order that are sorted by date and time in reverse order, you can use the command below.

almostengr@linuxtraining:/etc$ ls -altr
total 816
-rw-r--r--  1 root root        280 Jun 20  2014 fuse.conf
-rw-r--r--  1 root root       3663 Jun  9  2015 screenrc
-rw-r--r--  1 root root         34 Jan 27  2016 ld.so.conf
-rw-r--r--  1 root root        367 Jan 27  2016 bindresvport.blacklist
-rw-r--r--  1 root root      24301 Jul 15  2016 mime.types
-rw-r--r--  1 root root        449 Jul 15  2016 mailcap.order
-rw-r--r--  1 root root      14867 Oct 13  2016 ltrace.conf
-rw-r--r--  1 root root      19183 Dec 26  2016 services
-rw-r--r--  1 root root        887 Dec 26  2016 rpc
-rw-r--r--  1 root root       2932 Dec 26  2016 protocols
-rw-r--r--  1 root root        100 Apr 11  2017 sos.conf
-rw-r--r--  1 root root       1748 May 15  2017 inputrc
-rw-r--r--  1 root root         11 Jun 25  2017 debian_version
-rwxr-xr-x  1 root root        268 Jul 21  2017 rmt
-rw-r--r--  1 root root        604 Aug 13  2017 deluser.conf
-rw-r--r--  1 root root        703 Aug 21  2017 logrotate.conf
-rw-r--r--  1 root root       6920 Oct 27  2017 overlayroot.conf
-rw-r--r--  1 root root        722 Nov 16  2017 crontab
-rw-r--r--  1 root root       2683 Jan 17  2018 sysctl.conf
-r--r-----  1 root root        755 Jan 18  2018 sudoers
-rw-r--r--  1 root root       4141 Jan 25  2018 securetty
-rw-r--r--  1 root root      10550 Jan 25  2018 login.defs
-rw-r--r--  1 root root       1358 Jan 30  2018 rsyslog.conf
-rw-r--r--  1 root root       2584 Feb  1  2018 gai.conf
-rw-r--r--  1 root root        191 Feb  7  2018 libaudit.conf
-rw-r--r--  1 root root        111 Feb 13  2018 magic.mime
-rw-r--r--  1 root root        111 Feb 13  2018 magic
-rw-r--r--  1 root root       9048 Feb 13  2018 nanorc
-rw-r-----  1 root daemon      144 Feb 20  2018 at.deny
-rw-r--r--  1 root root       4861 Feb 22  2018 hdparm.conf
-rw-r--r--  1 root root       1260 Feb 26  2018 ucf.conf
-rw-r--r--  1 root root       2969 Feb 28  2018 debconf.conf
-rw-r--r--  1 root root        403 Mar  1  2018 updatedb.conf
-rw-r--r--  1 root root        477 Mar 16  2018 zsh_command_not_found
-rw-r--r--  1 root root        812 Mar 24  2018 mke2fs.conf
-rw-r--r--  1 root root         45 Apr  2  2018 bash_completion
-rw-r--r--  1 root root       2319 Apr  4  2018 bash.bashrc
-rw-r--r--  1 root root        552 Apr  4  2018 pam.conf
-rw-r--r--  1 root root       5174 Apr  7  2018 manpath.config
-rw-r--r--  1 root root        581 Apr  9  2018 profile
-rw-r--r--  1 root root         91 Apr  9  2018 networks
-rw-r--r--  1 root root        267 Apr  9  2018 legal
-rw-r--r--  1 root root         92 Apr  9  2018 host.conf
-rw-r--r--  1 root root       2995 Apr 16  2018 locale.alias
drwxr-xr-x  2 root root       4096 Apr 20  2018 binfmt.d
-rw-r--r--  1 root root       4942 May  8  2018 wgetrc
drwxrwxr-x  2 root landscape  4096 May 18  2018 landscape
-rw-r--r--  1 root root       1317 Jun 28  2018 ethertypes
drwxr-xr-x  2 root root       4096 Jul  2  2018 update-notifier
-rw-r--r--  1 root root        273 Jul 11  2018 hosts
drwxr-xr-x  2 root root       4096 Jul 25  2018 opt
drwxr-xr-x  2 root root       4096 Jul 25  2018 selinux
drwxr-xr-x  2 root root       4096 Jul 25  2018 ld.so.conf.d
-rw-------  1 root root          0 Jul 25  2018 .pwd.lock
-rw-r--r--  1 root root         96 Jul 25  2018 environment
lrwxrwxrwx  1 root root         39 Jul 25  2018 resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
-rw-r--r--  1 root root       3028 Jul 25  2018 adduser.conf
drwxr-xr-x  4 root root       4096 Jul 25  2018 dbus-1
drwxr-xr-x  3 root root       4096 Jul 25  2018 ca-certificates
-rw-r--r--  1 root root        513 Jul 25  2018 nsswitch.conf
-rw-r--r--  1 root root        195 Jul 25  2018 modules
-rw-r--r--  1 root root       5898 Jul 25  2018 ca-certificates.conf
drwxr-xr-x  2 root root       4096 Jul 25  2018 cron.monthly
drwxr-xr-x  2 root root       4096 Jul 25  2018 cron.hourly
drwxr-xr-x  4 root root       4096 Jul 25  2018 xdg
drwxr-xr-x  4 root root       4096 Jul 25  2018 iproute2
drwxr-xr-x  2 root root       4096 Jul 25  2018 python3
drwxr-xr-x  2 root root       4096 Jul 25  2018 newt
lrwxrwxrwx  1 root root         23 Jul 25  2018 vtrgb -> /etc/alternatives/vtrgb
drwxr-xr-x  2 root root       4096 Jul 25  2018 terminfo
lrwxrwxrwx  1 root root         19 Jul 25  2018 mtab -> ../proc/self/mounts
-rw-r--r--  1 root root        110 Jul 25  2018 kernel-img.conf
drwxr-xr-x  4 root root       4096 Jul 25  2018 fonts
drwxr-xr-x  4 root root       4096 Jul 25  2018 perl
drwxr-xr-x  3 root root       4096 Jul 25  2018 gss
drwxr-xr-x  3 root root       4096 Jul 25  2018 apm
drwxr-xr-x  3 root root       4096 Jul 25  2018 acpi
-rw-r--r--  1 root root         54 Jul 25  2018 crypttab
drwxr-xr-x  4 root root       4096 Jul 25  2018 network
drwxr-xr-x  4 root root       4096 Jul 25  2018 X11
drwxr-xr-x  3 root root       4096 Jul 25  2018 pm
drwxr-xr-x  6 root root       4096 Jul 25  2018 kernel
-rw-r--r--  1 root root         35 Jul 25  2018 subuid-
-rw-r--r--  1 root root         35 Jul 25  2018 subgid-
drwxr-xr-x  5 root root       4096 Jul 25  2018 polkit-1
drwxr-xr-x  4 root root       4096 Jul 25  2018 logcheck
drwxr-xr-x  2 root root       4096 Jul 25  2018 groff
drwxr-xr-x  2 root root       4096 Jul 25  2018 tmpfiles.d
-rw-r--r--  1 root root        103 Jul 25  2018 shells
drwxr-xr-x  2 root root       4096 Jul 25  2018 libnl-3
drwxr-xr-x  2 root root       4096 Jul 25  2018 calendar
-rw-r--r--  1 root root        350 Jul 25  2018 popularity-contest.conf
drwxr-xr-x  2 root root       4096 Jul 25  2018 byobu
-rw-r-----  1 root shadow      540 Jul 25  2018 gshadow-
-rw-r--r--  1 root root        648 Jul 25  2018 group-
drwxr-xr-x  2 root root       4096 Jul 25  2018 dnsmasq.d-available
drwxr-xr-x  2 root root       4096 Jul 25  2018 rcS.d
drwxr-xr-x  2 root root       4096 Jul 25  2018 dnsmasq.d
drwxr-xr-x  3 root root       4096 Jul 25  2018 NetworkManager
-rw-r--r--  1 root root        711 Jul 25  2018 hosts.deny
-rw-r--r--  1 root root        411 Jul 25  2018 hosts.allow
-rw-r-----  1 root shadow      804 Jul 25  2018 shadow-
-rw-r--r--  1 root root       1512 Jul 25  2018 passwd-
-rw-r--r--  1 root root        105 Jan 30 12:28 lsb-release
lrwxrwxrwx  1 root root         21 Jan 30 12:28 os-release -> ../usr/lib/os-release
-rw-r--r--  1 root root         19 Jan 30 12:28 issue.net
-rw-r--r--  1 root root         26 Jan 30 12:28 issue
drwxr-xr-x 23 root root       4096 Feb 23 21:03 ..
-rw-r--r--  1 root root         89 Feb 23 21:03 fstab
drwxr-xr-x  2 root root       4096 Feb 23 21:03 pollinate
-r--r--r--  1 root root         33 Feb 23 21:05 machine-id
drwxr-xr-x  2 root root       4096 Feb 23 21:05 netplan
-rw-r--r--  1 root root       1573 Feb 23 21:05 passwd
-rw-r-----  1 root shadow      941 Feb 23 21:05 shadow
-rw-r--r--  1 root root        728 Feb 23 21:05 group
-rw-r-----  1 root shadow      616 Feb 23 21:05 gshadow
-rw-r--r--  1 root root         59 Feb 23 21:05 subuid
-rw-r--r--  1 root root         59 Feb 23 21:05 subgid
-rw-r--r--  1 root root       9395 Feb 23 21:05 locale.gen
-rw-r--r--  1 root root         14 Feb 23 21:07 hostname
drwxr-xr-x  3 root root       4096 Feb 24 07:02 apparmor
drwxr-xr-x  4 root root       4096 Feb 24 07:05 dhcp
drwxr-xr-x  2 root root       4096 Feb 24 07:09 sudoers.d
-rw-r--r--  1 root root          8 Feb 24 07:09 timezone
lrwxrwxrwx  1 root root         27 Feb 24 07:09 localtime -> /usr/share/zoneinfo/Etc/UTC
drwxr-xr-x  4 root root       4096 Feb 24 07:13 ssl
drwxr-xr-x  2 root root       4096 Feb 24 07:14 ssh
drwxr-xr-x  2 root root       4096 Feb 24 07:14 vim
drwxr-xr-x  2 root root       4096 Feb 27 23:54 skel
drwxr-xr-x  2 root root       4096 Feb 27 23:54 alternatives
drwxr-xr-x  4 root root       4096 Feb 27 23:54 dpkg
drwxr-xr-x  2 root root       4096 Feb 27 23:54 modules-load.d
drwxr-xr-x  4 root root       4096 Feb 27 23:54 security
drwxr-xr-x  2 root root       4096 Feb 27 23:54 sysctl.d
drwxr-xr-x  5 root root       4096 Feb 27 23:54 systemd
drwxr-xr-x  7 root root       4096 Feb 27 23:54 apt
drwxr-xr-x  6 root root       4096 Feb 27 23:55 networkd-dispatcher
drwxr-xr-x  2 root root       4096 Feb 27 23:55 depmod.d
drwxr-xr-x  2 root root       4096 Feb 27 23:55 thermald
drwxr-xr-x  2 root root       4096 Feb 27 23:55 ldap
drwxr-xr-x  2 root root       4096 Feb 27 23:55 python3.6
drwxr-xr-x  4 root root       4096 Feb 27 23:55 udev
drwxr-xr-x  2 root root       4096 Feb 27 23:55 grub.d
drwxr-xr-x  2 root root       4096 Feb 27 23:56 console-setup
drwxr-xr-x  5 root root       4096 Feb 27 23:57 initramfs-tools
drwxr-xr-x  2 root root       4096 Feb 27 23:57 iscsi
drwxr-xr-x  2 root root       4096 Feb 27 23:57 cron.d
drwxr-xr-x  2 root root       4096 Feb 27 23:57 modprobe.d
drwxr-xr-x  2 root root       4096 Feb 27 23:57 mdadm
drwxr-xr-x  2 root root       4096 Feb 27 23:57 cryptsetup-initramfs
drwxr-xr-x  2 root root       4096 Feb 27 23:57 pam.d
drwxr-xr-x  4 root root       4096 Feb 27 23:57 vmware-tools
drwxr-xr-x  4 root root       4096 Feb 27 23:58 cloud
drwxr-xr-x  2 root root       4096 Feb 27 23:58 profile.d
drwxr-xr-x  2 root root       4096 Feb 27 23:58 rsyslog.d
drwxr-xr-x  3 root root       4096 Feb 27 23:58 ufw
drwxr-xr-x  3 root root       4096 Feb 27 23:58 apport
drwxr-xr-x  9 root root       4096 Feb 27 23:58 apparmor.d
drwxr-xr-x  3 root root       4096 Feb 27 23:58 lvm
drwxr-xr-x  3 root root       4096 Feb 27 23:58 update-manager
drwxr-xr-x  2 root root       4096 Feb 27 23:58 cron.daily
drwxr-xr-x  2 root root       4096 Feb 27 23:58 cron.weekly
drwxr-xr-x  2 root root       4096 Feb 27 23:58 update-motd.d
-rw-r--r--  1 root root      22686 Feb 27 23:58 ld.so.cache
drwxr-xr-x  2 root root       4096 Feb 28 01:58 python2.7
drwxr-xr-x  4 root root       4096 Feb 28 01:58 monit
drwxr-xr-x  2 root root       4096 Feb 28 01:58 bash_completion.d
drwxr-xr-x  3 root root       4096 Feb 28 01:58 default
drwxr-xr-x  6 root root       4096 Feb 28 01:58 fail2ban
drwxr-xr-x  2 root root       4096 Feb 28 01:58 init.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 logrotate.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 rc6.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 rc5.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 rc4.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 rc3.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 rc2.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 rc1.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 rc0.d
drwxr-xr-x  2 root root       4096 Feb 28 01:58 python
-rw-r--r--  1 root root       3623 Feb 28 01:58 mailcap
drwxr-xr-x 95 root root       4096 Feb 28 01:58 .

As you see, the most recent files will show up at the bottom of the screen. When there are a number of files in a directory, those files will flood the screen which means you will have to scroll back to see the files at the beginning.

The command ls -alt will place the most recently modified files at the top of the list and oldest files at the bottom. If you are looking for the oldest files, then you would not have to scroll back to find them.

It is possible to list the files by time without displaying the timestamp of when the file or directory was last modified. In most circumstances, this listing will not be useful as it will not have any of the date or time information presented.

almostengr@linuxtraining:/etc$ ls -1t
mailcap               systemd                  shells                host.conf
python                sysctl.d                 tmpfiles.d            legal
rc0.d                 security                 groff                 networks
rc1.d                 modules-load.d           logcheck              profile
rc2.d                 dpkg                     polkit-1              manpath.config
rc3.d                 alternatives             subgid-               pam.conf
rc4.d                 skel                     subuid-               bash.bashrc
rc5.d                 vim                      kernel                bash_completion
rc6.d                 ssh                      pm                    mke2fs.conf
logrotate.d           ssl                      X11                   zsh_command_not_found
init.d                localtime                network               updatedb.conf
fail2ban              timezone                 crypttab              debconf.conf
default               sudoers.d                acpi                  ucf.conf
bash_completion.d     dhcp                     apm                   hdparm.conf
monit                 apparmor                 gss                   at.deny
python2.7             hostname                 perl                  nanorc
ld.so.cache           locale.gen               fonts                 magic
update-motd.d         subgid                   kernel-img.conf       magic.mime
cron.weekly           subuid                   mtab                  libaudit.conf
cron.daily            gshadow                  terminfo              gai.conf
update-manager        group                    vtrgb                 rsyslog.conf
lvm                   shadow                   newt                  login.defs
apparmor.d            passwd                   python3               securetty
apport                netplan                  iproute2              sudoers
ufw                   machine-id               xdg                   sysctl.conf
rsyslog.d             pollinate                cron.hourly           crontab
profile.d             fstab                    cron.monthly          overlayroot.conf
cloud                 issue                    ca-certificates.conf  logrotate.conf
vmware-tools          issue.net                modules               deluser.conf
pam.d                 os-release               nsswitch.conf         rmt
cryptsetup-initramfs  lsb-release              ca-certificates       debian_version
mdadm                 passwd-                  dbus-1                inputrc
modprobe.d            shadow-                  adduser.conf          sos.conf
cron.d                hosts.allow              resolv.conf           protocols
iscsi                 hosts.deny               environment           rpc
initramfs-tools       NetworkManager           ld.so.conf.d          services
console-setup         dnsmasq.d                selinux               ltrace.conf
grub.d                rcS.d                    opt                   mailcap.order
udev                  dnsmasq.d-available      hosts                 mime.types
python3.6             group-                   update-notifier       bindresvport.blacklist
ldap                  gshadow-                 ethertypes            ld.so.conf
thermald              byobu                    landscape             screenrc
depmod.d              popularity-contest.conf  wgetrc                fuse.conf
networkd-dispatcher   calendar                 binfmt.d
apt                   libnl-3                  locale.alias

Listing Only Directories

You can list only the directories using the ls command. You have to use the */ in the command. This command may vary depending on the Linux distribution that you are using.

almostengr@linuxtraining:/etc$ ls -d */
acpi/               cryptsetup-initramfs/  ldap/                 polkit-1/   ssh/
alternatives/       dbus-1/                ld.so.conf.d/         pollinate/  ssl/
apm/                default/               libnl-3/              profile.d/  sudoers.d/
apparmor/           depmod.d/              logcheck/             python/     sysctl.d/
apparmor.d/         dhcp/                  logrotate.d/          python2.7/  systemd/
apport/             dnsmasq.d/             lvm/                  python3/    terminfo/
apt/                dnsmasq.d-available/   mdadm/                python3.6/  thermald/
bash_completion.d/  dpkg/                  modprobe.d/           rc0.d/      tmpfiles.d/
binfmt.d/           fail2ban/              modules-load.d/       rc1.d/      udev/
byobu/              fonts/                 monit/                rc2.d/      ufw/
ca-certificates/    groff/                 netplan/              rc3.d/      update-manager/
calendar/           grub.d/                network/              rc4.d/      update-motd.d/
cloud/              gss/                   networkd-dispatcher/  rc5.d/      update-notifier/
console-setup/      init.d/                NetworkManager/       rc6.d/      vim/
cron.d/             initramfs-tools/       newt/                 rcS.d/      vmware-tools/
cron.daily/         iproute2/              opt/                  rsyslog.d/  X11/
cron.hourly/        iscsi/                 pam.d/                security/   xdg/
cron.monthly/       kernel/                perl/                 selinux/
cron.weekly/        landscape/             pm/                   skel/

Another way to list the files with the directories is to run the following command. This command will put a trailing slash on each item that is a directory. Files do not have slashes.

almostengr@linuxtraining:/etc$ ls -F
acpi/                   groff/            manpath.config           rmt*
adduser.conf            group             mdadm/                   rpc
alternatives/           group-            mime.types               rsyslog.conf
apm/                    grub.d/           mke2fs.conf              rsyslog.d/
apparmor/               gshadow           modprobe.d/              screenrc
apparmor.d/             gshadow-          modules                  securetty
apport/                 gss/              modules-load.d/          security/
apt/                    hdparm.conf       monit/                   selinux/
at.deny                 host.conf         mtab@                    services
bash.bashrc             hostname          nanorc                   shadow
bash_completion         hosts             netplan/                 shadow-
bash_completion.d/      hosts.allow       network/                 shells
bindresvport.blacklist  hosts.deny        networkd-dispatcher/     skel/
binfmt.d/               init.d/           NetworkManager/          sos.conf
byobu/                  initramfs-tools/  networks                 ssh/
ca-certificates/        inputrc           newt/                    ssl/
ca-certificates.conf    iproute2/         nsswitch.conf            subgid
calendar/               iscsi/            opt/                     subgid-
cloud/                  issue             os-release@              subuid
console-setup/          issue.net         overlayroot.conf         subuid-
cron.d/                 kernel/           pam.conf                 sudoers
cron.daily/             kernel-img.conf   pam.d/                   sudoers.d/
cron.hourly/            landscape/        passwd                   sysctl.conf
cron.monthly/           ldap/             passwd-                  sysctl.d/
crontab                 ld.so.cache       perl/                    systemd/
cron.weekly/            ld.so.conf        pm/                      terminfo/
cryptsetup-initramfs/   ld.so.conf.d/     polkit-1/                thermald/
crypttab                legal             pollinate/               timezone
dbus-1/                 libaudit.conf     popularity-contest.conf  tmpfiles.d/
debconf.conf            libnl-3/          profile                  ucf.conf
debian_version          locale.alias      profile.d/               udev/
default/                locale.gen        protocols                ufw/
deluser.conf            localtime@        python/                  updatedb.conf
depmod.d/               logcheck/         python2.7/               update-manager/
dhcp/                   login.defs        python3/                 update-motd.d/
dnsmasq.d/              logrotate.conf    python3.6/               update-notifier/
dnsmasq.d-available/    logrotate.d/      rc0.d/                   vim/
dpkg/                   lsb-release       rc1.d/                   vmware-tools/
environment             ltrace.conf       rc2.d/                   vtrgb@
ethertypes              lvm/              rc3.d/                   wgetrc
fail2ban/               machine-id        rc4.d/                   X11/
fonts/                  magic             rc5.d/                   xdg/
fstab                   magic.mime        rc6.d/                   zsh_command_not_found
fuse.conf               mailcap           rcS.d/
gai.conf                mailcap.order     resolv.conf@

Different Way Of Listing Only CSV Files In Directory

You can use the grep command to filter out the list of files and directories using the pipe | character.

In the example below, the output of the ls command is "piped" to the grep command and then displayed.

almostengr@linuxtraining:~$ ls -l | grep csv
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 copiedfile.csv
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 data2.csv
-rw-rw-r-- 1 almostengr almostengr 6538 Mar  1 05:39 data.csv

The command above, will return the same command as below.

almostengr@linuxtraining:~$ ls -l *csv
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 copiedfile.csv
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 data2.csv
-rw-rw-r-- 1 almostengr almostengr 6538 Mar  1 05:39 data.csv

Searching Files and Output with grep

You can use grep to find certain strings or patterns in a file. The help documentation for the command can be found by running the command below.

almostengr@linuxtraining:~$ grep --help

Below I have used the command and piped it to more to show the lines in the file that contain "s".

almostengr@linuxtraining:~$ grep s data2.csv | more
id,first_name,last_name,email,region,country
1,Christian,Walls,non.hendrerit.id@a.net,Manitoba,Spain
2,Mona,Morales,pulvinar.arcu.et@lacusEtiam.ca,Cusco,Mongolia
3,Channing,Ford,ipsum.dolor.sit@id.ca,Metropolitana de Santiago,Faroe Islands
4,Aurora,Lucas,dis.parturient.montes@Proin.net,Waals-Brabant,Montserrat
5,John,Hunter,Cras.eu.tellus@Integerurna.ca,Andhra Pradesh,Sierra Leone
6,Abdul,Shepherd,sed@vestibulumnequesed.com,ATL,Dominican Republic
7,Whilemina,Washington,consectetuer.adipiscing.elit@dolor.net,AQ,Syria
8,Chantale,Rivas,non.vestibulum@Cras.co.uk,SL,Moldova
9,Marcia,Quinn,ante@risus.org,Loreto,Malawi
10,Alexander,Alvarado,vulputate@ametfaucibusut.net,QC,Hong Kong
11,Odessa,Phelps,ac.mi.eleifend@mus.com,Antioquia,Liechtenstein
12,Hammett,Rowe,tincidunt.aliquam.arcu@Donecegestas.co.uk,SJ,Malta
13,Kasimir,Bentley,pellentesque.massa.lobortis@Integeraliquam.ca,East Kalimantan,Fiji
14,Macon,Stone,varius.ultrices.mauris@ornarelectusjusto.com,JT,Macao
15,Abdul,Dejesus,eget@ridiculus.co.uk,Hamburg,Israel
16,Raphael,Harrington,mattis.Cras@est.co.uk,Irkutsk Oblast,Mauritania
17,Thane,Williams,diam.vel.arcu@aptenttaciti.ca,NGR,Heard Island and Mcdonald Islands
18,Lucian,Sexton,ipsum.Suspendisse.sagittis@velconvallis.ca,Assam,Fiji
19,Destiny,Hampton,ligula.elit.pretium@a.edu,BC,Wallis and Futuna
20,Anjolie,Bates,id.mollis.nec@semper.ca,NSW,Cape Verde
21,Adena,Dickson,Quisque@estMauriseu.net,MO,Macao
22,Cassandra,Cherry,nec@diamnuncullamcorper.com,MP,Botswana
23,Nigel,Holden,et@varius.co.uk,IV,"Saint Helena, Ascension and Tristan da Cunha"
24,Sylvester,Thornton,Cras@utnullaCras.co.uk,QC,Mexico
--More--

The grep command is case-sensitive. As you can see, the lower case "s" returns a different number of rows than the upper case "S" from the same file.

almostengr@linuxtraining:~$ grep s data2.csv | more wc -l
97
almostengr@linuxtraining:~$ grep S data2.csv | wc -l
46

A case-insensitive search can be done by using the -i option. The below command was run and returned a all of the lines that contained a "S" whether it was upper or lowercase.

almostengr@linuxtraining:~$ grep -i S data2.csv | wc -l
99

Difference Between Pipe and Output

In the examples above, I piped the output from one command to another command. It was asked if | is the same as using >>, to which I answered that it was not. I ran the commands below to demonstrate the differences.

When using the pipe command, the output is passed to the next command after the pipe. In this example, it resulted in the number of lines being displayed on the screen and no file being created.

almostengr@linuxtraining:~$ ls -al | wc -l
20
almostengr@linuxtraining:~$ ls
almostengr.txt  copyofsample2.txt  data2.csv  dirtocopy
copiedfile.csv  copyofsample.txt   data.csv   kenny.txt

When using the append command, the output is passed to the filename that comes after the double arrowss. in this e example, it resulted in the output of the ls command being written to a file named wc.

almostengr@linuxtraining:~$ ls -al >> wc -l
almostengr@linuxtraining:~$ ls
almostengr.txt  copyofsample2.txt  data2.csv  dirtocopy  wc
copiedfile.csv  copyofsample.txt   data.csv   kenny.txt

When viewing the contents of the file named "wc", we see a listing of files and directories.

almostengr@linuxtraining:~$ more wc
total 80
drwxr-xr-x 6 almostengr almostengr 4096 Mar  1 22:47 .
drwxr-xr-x 3 root       root       4096 Feb 23 21:05 ..
-rw-rw-r-- 1 almostengr almostengr  790 Feb 24 03:11 almostengr.txt
-rw------- 1 almostengr almostengr 2340 Mar  1 17:32 .bash_history
-rw-r--r-- 1 almostengr almostengr  220 Apr  4  2018 .bash_logout
-rw-r--r-- 1 almostengr almostengr 3771 Apr  4  2018 .bashrc
drwx------ 2 almostengr almostengr 4096 Feb 23 21:05 .cache
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 copiedfile.csv
-rw-rw-r-- 1 almostengr almostengr    0 Mar  1 22:17 copyofsample2.txt
-rw-rw-r-- 1 almostengr almostengr    0 Mar  1 22:17 copyofsample.txt
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 data2.csv
-rw-rw-r-- 1 almostengr almostengr 6538 Mar  1 05:39 data.csv
drwxrwxr-x 2 almostengr almostengr 4096 Feb 24 03:17 dirtocopy
drwx------ 3 almostengr almostengr 4096 Feb 23 21:05 .gnupg
-rw-rw-r-- 1 almostengr almostengr  576 Feb 24 03:11 kenny.txt
-rw-r--r-- 1 almostengr almostengr  807 Apr  4  2018 .profile
-rw-r--r-- 1 almostengr almostengr    0 Feb 23 21:06 .sudo_as_admin_successful
drwxr-xr-x 2 almostengr almostengr 4096 Mar  1 05:39 .vim
-rw------- 1 almostengr almostengr 6805 Mar  1 05:40 .viminfo
-rw-rw-r-- 1 almostengr almostengr    0 Mar  1 22:47 wc

Look At Previous Commands Ran

To see the previous commands that you have ran, you can run the history command. To filter that list, you can use the grep command. In this scenario, I was grepping for the grep command. Thus why it is listed twice after the pipe.

almostengr@linuxtraining:~$ history | grep grep
    2  ifconfig | grep 192
  231  ps -ef | grep almostengr
  343  ls -l | grep csv
  345  grep s data2.csv | more
  346  grep s data2.csv | wc -l
  347  grep S data2.csv | wc -l
  348  grep --help
  349  grep s data2.csv | more
  350  grep s data2.csv | wc -l
  352* grep -i S data2.csv
  353  grep -i q data2.csv | wc -l
  361  history | grep grep

Using the wc Command

almostengr@linuxtraining:~$ grep -i q data2.csv | wc -l
30

I filtered the data file by only including rows that have a "q" in them into another file. Then I counted the number of lines in that file using the wc command.

almostengr@linuxtraining:~$ grep -i q data2.csv >> filrowswithq.txt
almostengr@linuxtraining:~$ wc rowswithq.txt
  30   49 1999 rowswithq.txt

Using vi

Those that attended the session got some experience using vi. That output was not easily captured by PuTTY log utility, so it was excluded from this blog post.

After creating and adding text to a file in vi, the attendees were shown how to display the contents of their file as well as grep the contents of the file they had created.

Below are the commands that were run for this.

almostengr@linuxtraining:~$ cat editingfile.txt
kasdfj;kalsdfjoai5rj;eafk
lkvn;aovn 9042a
the quick brown fox
jumped over the lazy
brown dog
almostengr@linuxtraining:~$ grep brown editingfile.txt
the quick brown fox
brown dog

grep found two lines in the file that matched the string or pattern provided.

almostengr@linuxtraining:~$ grep BROWN editingfile.txt

No output was returned from the command above because the pattern did not exist in the file.

almostengr@linuxtraining:~$ grep -i BROWN editingfile.txt
the quick brown fox
brown dog

grep found two lines in the file that matched the string or pattern provided as the ignore case option was used.

almostengr@linuxtraining:~$ rm editingfile.txt && ls
almostengr.txt  copyofsample2.txt  data2.csv  dirtocopy  rowswithq.txt
copiedfile.csv  copyofsample.txt   data.csv   kenny.txt  wc

Aliases and Example Usage

almostengr@linuxtraining:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

Aliases with Debugging Enabled

To turn on debugging, you run the command below. The command will not return any output.

almostengr@linuxtraining:~$ set -x
almostengr@linuxtraining:~$ ls

To confirm that it is on, run any other command (in this case ls) and you will see a line that begins with +. The line with "+" comes from the debugger.

+ ls --color=auto
almostengr.txt  copyofsample2.txt  data2.csv  dirtocopy  rowswithq.txt
copiedfile.csv  copyofsample.txt   data.csv   kenny.txt  wc

To turn off debugging, you run the command below. The command will not return any output

almostengr@linuxtraining:~$ set +x

To see all of the aliases that have been set, type alias in the prompt.

almostengr@linuxtraining:~$ alias
+ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
almostengr@linuxtraining:~$ grep data

Double tapping the Tab key after entering the above in the prompt, resulted in the below output.

+ local cur prev words cword split
+ _init_completion -s
+ local exclude= flag outx errx inx OPTIND=1
+ getopts n:e:o:i:s flag -s
+ case $flag in
+ split=false
+ exclude+==
+ getopts n:e:o:i:s flag -s
+ COMPREPLY=()
+ local 'redir=@(?([0-9])<|?([0-9&])>?(>)|>&)'
+ _get_comp_words_by_ref -n '=<>&' cur prev words cword
+ local exclude flag i OPTIND=1
+ words=()
+ local cur cword words
+ upargs=()
+ upvars=()
+ local upargs upvars vcur vcword vprev vwords
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ case $flag in
+ exclude='=<>&'
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ [[ 6 -ge 3 ]]
+ case ${!OPTIND} in
+ vcur=cur
+ let 'OPTIND += 1'
+ [[ 6 -ge 4 ]]
+ case ${!OPTIND} in
+ vprev=prev
+ let 'OPTIND += 1'
+ [[ 6 -ge 5 ]]
+ case ${!OPTIND} in
+ vwords=words
+ let 'OPTIND += 1'
+ [[ 6 -ge 6 ]]
+ case ${!OPTIND} in
+ vcword=cword
+ let 'OPTIND += 1'
+ [[ 6 -ge 7 ]]
+ __get_cword_at_cursor_by_ref '=<>&' words cword cur
+ words=()
+ local cword words
+ __reassemble_comp_words_by_ref '=<>&' words cword
+ local exclude i j line ref
+ [[ -n =<>& ]]
+ exclude='=<>&'
+ printf -v cword %s 1
+ [[ -n =<>& ]]
+ line='grep data'
+ (( i=0, j=0 ))
+ (( i < 2 ))
+ [[ 0 -gt 0 ]]
+ ref='words[0]'
+ printf -v 'words[0]' %s grep
+ line=' data'
+ [[ 0 == 1 ]]
+ (( i++, j++ ))
+ (( i < 2 ))
+ [[ 1 -gt 0 ]]
+ [[ data == +([=<>&]) ]]
+ ref='words[1]'
+ printf -v 'words[1]' %s data
+ line=
+ [[ 1 == 1 ]]
+ printf -v cword %s 1
+ (( i++, j++ ))
+ (( i < 2 ))
+ [[ 2 == 1 ]]
+ local i cur index=9 'lead=grep data'
+ [[ 9 -gt 0 ]]
+ [[ -n grep data ]]
+ [[ -n grepdata ]]
+ cur='grep data'
+ (( i = 0 ))
+ (( i <= cword ))
+ [[ 9 -ge 4 ]]
+ [[ grep != \g\r\e\p ]]
+ [[ 0 -lt 1 ]]
+ local old_size=9
+ cur=' data'
+ local new_size=5
+ index=5
+ (( ++i  ))
+ (( i <= cword ))
+ [[ 5 -ge 4 ]]
+ [[  dat != \d\a\t\a ]]
+ cur=data
+ [[ 5 -gt 0 ]]
+ (( index-- ))
+ [[ 4 -ge 4 ]]
+ [[ data != \d\a\t\a ]]
+ [[ 1 -lt 1 ]]
+ (( ++i  ))
+ (( i <= cword ))
+ [[ -n data ]]
+ [[ ! -n data ]]
+ [[ 4 -lt 0 ]]
+ local words cword cur
+ _upvars -a2 words grep data -v cword 1 -v cur data
+ ((  10  ))
+ ((  10  ))
+ case $1 in
+ [[ -n 2 ]]
+ printf %d 2
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:2}")'
++ words=("${@:3:2}")
+ shift 4
+ ((  6  ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=1
+ shift 3
+ ((  3  ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=data
+ shift 3
+ ((  0  ))
+ [[ -n cur ]]
+ upvars+=("$vcur")
+ upargs+=(-v $vcur "$cur")
+ [[ -n cword ]]
+ upvars+=("$vcword")
+ upargs+=(-v $vcword "$cword")
+ [[ -n prev ]]
+ [[ 1 -ge 1 ]]
+ upvars+=("$vprev")
+ upargs+=(-v $vprev "${words[cword - 1]}")
+ [[ -n words ]]
+ upvars+=("$vwords")
+ upargs+=(-a${#words[@]} $vwords "${words[@]}")
+ ((  4  ))
+ local cur cword prev words
+ _upvars -v cur data -v cword 1 -v prev grep -a2 words grep data
+ ((  13  ))
+ ((  13  ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=data
+ shift 3
+ ((  10  ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=1
+ shift 3
+ ((  7  ))
+ case $1 in
+ [[ -n prev ]]
+ unset -v prev
+ eval 'prev="$3"'
++ prev=grep
+ shift 3
+ ((  4  ))
+ case $1 in
+ [[ -n 2 ]]
+ printf %d 2
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:2}")'
++ words=("${@:3:2}")
+ shift 4
+ ((  0  ))
+ _variables
+ [[ data =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]
+ [[ data =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]
+ [[ data =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*]$ ]]
+ case $prev in
+ return 1
+ [[ data == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ [[ grep == @(?([0-9])<|?([0-9&])>?(>)|>&) ]]
+ local i skip
+ (( i=1 ))
+ (( i < 2 ))
+ [[ data == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=2
+ (( 1 ))
+ (( i < 2 ))
+ [[ 1 -le 0 ]]
+ prev=grep
+ [[ -n false ]]
+ _split_longopt
+ [[ data == --?*=* ]]
+ return 1
+ return 0
+ case "${prev,,}" in
+ false
+ [[ data == -* ]]
+ [[ grep == @(rmdir|chroot) ]]
+ [[ grep == mkdir ]]
+ _filedir
+ local 'IFS=
'
+ _tilde data
+ local result=0
+ [[ data == \~* ]]
+ return 0
+ local -a toks
+ local x tmp
++ compgen -d -- data
+ x=
+ [[ '' != -d ]]
+ local quoted
+ _quote_readline_by_ref data quoted
+ '[' -z data ']'
+ [[ data == \'* ]]
+ [[ data == \~* ]]
+ printf -v quoted %q data
+ [[ data == *\\* ]]
+ [[ data == \$* ]]
+ local xspec=
++ compgen -f -X '' -- data
+ x='data2.csv
data.csv'
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ [[ -n '' ]]
+ [[ 2 -ne 0 ]]
+ compopt -o filenames
+ COMPREPLY+=("${toks[@]}")

The above output is all of the commands that are being run in the background to perform the auto-complete functionality.

To create an alias, you can run the command below. The command will not return output unless you have debugging enabled.

almostengr@linuxtraining:~$ alias power="ls -al | grep csv"

To use the alias, enter it on the prompt.

almostengr@linuxtraining:~$ power
+ grep --color=auto csv
+ ls --color=auto -al
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 copiedfile.csv
-rw-rw-r-- 1 almostengr almostengr 6595 Mar  1 05:40 data2.csv
-rw-rw-r-- 1 almostengr almostengr 6538 Mar  1 05:39 data.csv
Updated: 2020-07-15 | Posted: 2020-03-01