Skip to main content

Posts

Showing posts with the label Vi/Vim

Linux vim/vi switch from 1st line to the last line

In Linux vim or vi is a must tool to learn on the command line. Editing .conf or configuration file, checking .log files or editing scripts and other tasks that requires editing will need to a vi or vim to read and edit. However, nano text editor is another version that is quite straight forward to use as well for text editing.  It is still good to have a vi/vim on a skill set of sysadmins, since vim or vi was already in Linux or Unix system before nano was introduced. Editing, checking or viewing a large file requires navigation. Of course, arrow keys are their tom move forward, upward or whatever direction is needed. Viewing 1000 or more lines and using arrow keys to move from 1st line to the last line will take sometimes if only arrow up and arrow down will be used. In vi / vim to quickly navigate from 1st line to last line no matter how big the file is can easily be done using some commands. Open a text file with number of lines using vim. Using :1, or :$ is the command to swit...

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,...