Skip to main content

Posts

Showing posts with the label Vi/Vim

View files in Linux from old to latest aka chronological order

Viewing files in Linux terminal from old to latest, is one of the common tasks a Linux sysadmin will do. And this can be done simply with the good ls command. Plus add a few parameters to make the output more readable and friendly. ls -lhtra this command will view all the files, hidden or not hidden from old to latest Example image below, shows all files; arrange in chronological order. ls -1  the command is ls - plus the number one not the small letter "L"; this is quite useful if need to get the filenames only on a specific directory and feed to xargs command or as an input on any bash script for further processing. Example, typing ls - 1 will output only the filenames on a specific directory. That's it till next time. Enjoy Linux and keep learning. Keep praying and stay open to God's messages. Fiat Voluntas Tua | Catholic Prayers & Quotes

Viewing files with line numbers in Linux terminal

 Reading files is basic and a must when working on the terminal in Linux or command line. There are a lot of ways to do this, a simple task but quite a few ways to accomplish it. Nano, vi/vim the most common editor in Linux that is part of the package in most Linux flavors if not all. In nano editor, while the file is open pressing "alt + n", will display the line numbering on the left side of the screen. Example image: In vi or vim, opening the file and typing the command: "set nu" or "set number" will also view the lines on the left side of the screen. Example image:   Or from the command line itself using "cat -n any_file_name.txt" will also view line numbers the -n is a parameter on cat to view or include the line numbers when displaying the file. Example image: less -N, command will also produce same result. Or just use nl , "man nl" shows:  NAME        nl - number lines of files It comes pre-installed in almost any Linux flavors,...