Navigating the Filesystem in BASH

From bib. source

The following commands exemplify the Bash syntax and enable users to begin working with the files and directories that make up Linux.

The primary commands, and their syntax, relevant to navigation of the file-system on Linux are (Garn 2022, 11):

commandpurposeexampleresult
lsList contents of the current directoryls /tmpList the contents of the /tmp directory
touchCreate a new empty file or update the timestamp of an existing filetouch newfile.txtCreate a new file named “newfile.txt”
cdChange from one directory to anothercd /etcChanges the current directory to /etc
catDisplay the contents of a text file on the screencat data.txtDisplay the contents of the data.txt file
lessDisplay the contents of a file in windows that fit on the screenless data.txtDisplay the contents of the data.txt file screen at a time when the file would not normally fit on one screen
treeDisplay the directory structure in a tree formattree /etcDisplay the subdirectories and files in the /etc directory in a tree structure

Correcting the record

It is more accurate to say the purpose of the primary command ls is to list the files and subdirectories of a directory–that is, to list the contents of a directory, and that when taking no argument it assumes the current directory as argument. Similarly, the purpose of the primary command cd is to change the current directory to the directory path that is its argument, but when taking no argument it assumes the home directory of the current user as that argument. Further, the true purpose of the primary command cat is to concatenate the contents of the filepaths it takes as arguments. Nonetheless, because it outputs the result to the screen, it is often used simply to display the contents of any given file in the shell.

Command alternatives

The primary command less can be replaced with more or most. The only difference is that more has limited backward navigation compared to less, and that most is just less with the ability to: (a) open more than one file simultaneously, (b) close one file at a time from those files, (c) lock the open windows for files, and (d) scroll across file windows and not just pages (Rinzwind 2019).

In addition, the command pwd can display to the screen, or print to the shell, the current directory the user is at during the shell session (Linuxize 2019). For example:

pwd

Current directory as environment variable

Primary commands like cd and ls can be understood as making use of what current directory the user is at, given certain arguments or the lack thereof. This implies that whatever the current directory is kept track of, likely inside an environment variable.

Finally, the tail primary command takes a filepath or filename as argument, and then displays in the shell, by default, the last lines of the file (Garn 2022, 43). The number of lines to be displayed can be adjusted through command options (to know what they are, refer to the man pages).

kernel operating_system file-system file_path Bourne_Again_Shell bash_script bash_scripting bash shell_script shell_scripting shell linguistics file_path file_paths filepaths directory_path directories subdirectory file home_directory users shell_script shell_scripting bash bash_script bash_scripting Bourne_Again_Shell Bourne_Again_Shell_script Bourne_Again_Shell_scripting environment_variable environment_variables command_line command-line command_lines command-lines Linux


bibliography