12
Navigating within the GNU/Linux Filesystem - Version.1 Navigating within the GNU/Linux Filesystem The purpose of this section is to provide a few basic GNU/Linux commands to aide new users locate areas on the ODU Turing cluster. The commands presented are a limited sample of the total population of standard commands on various GNU/Linux platforms. There are several assumptions regarding the users reading this section. Prerequisites The user has experience with some type of desktop computer with input devices that are a keyboard and mouse, or are capable of duplicating the functions of a keyboard and mouse (in short, you have used a computer prior to going through this aide). The user has network access and sufficient user credentials to connect to the ODU Turing cluster. {Note: If that is not true please refer to the “Prerequisites” and/or the “Connecting to the ODU “Turing” Cluster” sections of this document.} Section Terminology file - data/document that has a name, stored on a computer directory - a container, with a name that holds files stored on a computer filesystem - the hierarchy/method in which directories and files are stored on a computer or device permissions - limitations to the access given to a file or directory as read (view/open the file/directory), write (change or add a file/directory), and/or execute (run a file) Flags (switches) - additional command options that can be added when running an application pipe ([Shift] + [|]) - a vertical line used in scripts/commands to take the output from one command and use it as input to another command. Information Technology Services - High Performance Computing Group 1 of 12

Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Embed Size (px)

Citation preview

Page 1: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

Navigating within the GNU/Linux Filesystem

The purpose of this section is to provide a few basic GNU/Linux commands to aide new users locate areas on the ODU Turing cluster. The commands presented are a limited sample of the total population of standard commands on various GNU/Linux platforms. There are several assumptions regarding the users reading this section.

Prerequisites

❏ The user has experience with some type of desktop computer with input devices that are a keyboard and mouse, or are capable of duplicating the functions of a keyboard and mouse (in short, you have used a computer prior to going through this aide).

❏ The user has network access and sufficient user credentials to connect to the ODU Turing cluster. {Note: If that is not true please refer to the “Prerequisites” and/or the “Connecting to the ODU “Turing” Cluster” sections of this document.}

Section Terminology

● file - data/document that has a name, stored on a computer

● directory - a container, with a name that holds files stored on a computer

● filesystem - the hierarchy/method in which directories and files are stored on a computer or device

● permissions - limitations to the access given to a file or directory as read (view/open the file/directory), write (change or add a file/directory), and/or execute (run a file)

● Flags (switches) - additional command options that can be added when running an application

● pipe ([Shift] + [|]) - a vertical line used in scripts/commands to take the output from

one command and use it as input to another command.

Information Technology Services - High Performance Computing Group 1 of 12

Page 2: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

The command prompt and shellUpon logging into the Turing cluster, a blinking cursor is presented along side a box with information in it. This is often referred to as the command prompt. The command prompt uses a set of commands that are understood by the shell. The shell is a type of application that interprets commands, and then communicates them to the operating system. The prompt, excluding the cursor, has three main parts; the username, the cluster node (machine name), and the current working directory. In the example the “~” (tilde) is an alias (synonym for “also known as”) for the user’s home directory (user’s personal directory).

Traditional Shell (tcsh) The Turing cluster has been configured to default to the traditional shell better known as tcsh. Though several benefits of using this shell exist, three (3) particular features will be highlighted.

1. Case sensitivityThe Linux operating system in general is case-sensitive. What this means to the user is that given the three (3) files “filename.txt”, “FILENAME.TXT”, and “FileName.TxT”; each of the listed filenames would be considered completely separate and different by the operating system. In other words, if a user wanted to edit “filename.txt” but typed in “FILENAME.TXT”, because the [Caps Lock] was turned on; the system would not correct for the mistake, and would likely return “FILENAME.TXT: Command not found.”

2. [Tab] completion Tab completion allows a user at the command prompt to type a few characters of a wanted command (also works with files, and directories), and then (assuming the command is in the path) complete the command by pressing the [Tab] button on the keyboard. This becomes particularly useful when typing the names of files with long names, odd names, or paths to data. This feature can save the user a great deal of time if used consistently.

3. Command historyOften commands are used repetitively while at the prompt. The commands entered into the command prompt can be seen, and reused by pressing the up arrow [↑] on the

Information Technology Services - High Performance Computing Group 2 of 12

Page 3: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

keyboard repeatedly. Though very useful it should be noted that there is a limit to the number of commands saved. The commands are also only held locally to the terminal or ssh session.

Basic Linux commands

● man command_name - opens the manual for the majority of most commands. ○ i.e. man pwd produces the manual entry for the print working directory command ○ navigate the manual using the up [↑] and down [↓] arrow keys, or the [Page Up]

and [Page Down] keys ○ quit the manual by pressing the [Q] key

● pwd - print working directory, displays the path to the current directory. This can be used to determine where the user is currently located in the filesytem

○ i.e. If pwd was run while in a user’s home directory (~) on Turing, the output would be /home/username

● ls (the l is a lowercase L)- lists is the contents of a directory {Note: in Microsoft Windows this would be similar to double-clicking a directory to view the contents}

○ ls can be used to view the contents of not only the current working directory, but also other directories in the filesystem. (i.e. ls /bin would list the contents of the /bin directory)

○ ls is commonly used with additional switches such as -a (show all files), -l (long view), or in combinations such as ls -la {Note: the files/directories beginning with a “.” are hidden}

Information Technology Services - High Performance Computing Group 3 of 12

Page 4: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

● mkdir directory_name - make directory, creates directories with a given name

● cd directory_name - change directory, changes working directory locations○ {Note: cd ~ always returns a user to the /home/username working directory}

Information Technology Services - High Performance Computing Group 4 of 12

Page 5: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

● cp /current_file_location/filename /new_file_location/file_name - copy, makes a copy of a file or directory from one location in another location

○ {Note: directories can be copied by using the -r switch (i.e. cp -r /current_directory_location /new_directory_location)

○ Initial copied files or directories are not destroyed

● mv /current_file_location/filename /new_file_location/file_name - move, makes a transfers of a file or directory from one location in another location

○ Initial moved files or directories are destroyed

Information Technology Services - High Performance Computing Group 5 of 12

Page 6: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

● rm filename - remove, deletes a file or directory○ {Note: to remove a directory, use the -r switch}

● more filename - views the text of a file, one page at a time○ navigate the text by using the up [↑] and down [↓] arrow keys, [Space] bar, or the

[Page Up] and [Page Down] keys ○ quit the manual by pressing the [Q] key

Information Technology Services - High Performance Computing Group 6 of 12

Page 7: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

● cat filename - concatenate, although design to append files, cat is most often used to view data within files

● grep expression filename - outputs the result of a search based on an expression in a given file

○ {Note: grep is most commonly used in combination or piped with other commands such as more or cat}

Information Technology Services - High Performance Computing Group 7 of 12

Page 8: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

● ./scriptname - the command ./ (dot-slash) allows a users to run an application or script

● chmod (switches) filename - change file mode bits, use to adjust the permissions on a file. The common permissions include adding (+) or removing (-) read (r), write (w), and execute (x).

Information Technology Services - High Performance Computing Group 8 of 12

Page 9: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

Text Editors in the Command Line ShellA text editor is an application that allows an user to create, and modify files from the command line. This section will specifically identify two editors though others exist. The two editors discussed in this document are vi and nano.

vi BasicsThe text editor vi (visual mode) has existed since 1976 as an editor in the UNIX operating system. Since that time many features, through the form of keyboard commands and shortcuts, have been added to the software. An improved version of vi was written and named vim (vi improved). Most commands found in vi also work within vim while providing additional features. {Note: This document provides very minimal techniques in the utilization of vi. Further techniques and features can be found through a man vi or an internet and/or internet video search for tutorials.}

Creating/Opening a filevi filename - this command creates or opens a document with the filename given in the current working directory, and starts a vi session

Information Technology Services - High Performance Computing Group 9 of 12

Page 10: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

Command mode and Insert modeDue to the time period in which vi was originally developed, it contains two primary modes. The first mode is the command mode that is entered by pressing the [Esc] key. The second mode is the insert or editing mode, and can be entered from within the command mode by pressing the [ i ] key. {Note: To enter text into a document, the user must be in the insert mode which can be reached by pressing the letter i on the keyboard while in the command mode. If unsure which mode currently in, press the [Esc] key to enter command mode.}

● Command Mode = [Esc]● Insert Text Mode = [Esc] and then press [ i ]

Write (Save)Information not saved in a file is considered to reside in the buffer. To save the information to a file, the information in the buffer must be written into the file. To do this, from the command mode the user must type :w and press [Enter].

● Write (save) to a file - Press [Esc] then type :w and lastly press [Enter]

Quit (Exiting vi)

Information Technology Services - High Performance Computing Group 10 of 12

Page 11: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

Exiting vi can take two forms. The first exits and does not save any changes in the buffer, and the second writes the changes in the buffer to a file and then exits to the command prompt.

● Quit without writing buffer (no save) - Press [Esc] then type :q! and lastly press [Enter]● Quit and write out the buffer (save) - Press [Esc] then type :wq and lastly press [Enter]

nano BasicsNano’s ANOther (nano) editor is a small, easy to use command line text editor.

Creating/Opening a filenano filename - this command creates or opens a document with the filename given in the current working directory, and starts a nano session. Use the keyboard arrows to move the cursor around the session window. Text can be typed freely as well as, additional functions at the bottom of the screen can be accessed with the use of the [Ctrl] button (^ is the symbol for the [Ctrl] button) plus the letter shown.

Information Technology Services - High Performance Computing Group 11 of 12

Page 12: Navigating within the GNU/Linux Filesystem - ODU · Navigating within the GNU/Linux Filesystem - Version.1 rm filename - remove, deletes a file or directory {Note: to remove a directory,

Navigating within the GNU/Linux Filesystem - Version.1

WriteOut (Save)Information not saved in a file is considered to reside in the buffer. To save the information to a file, the information in the buffer must be written into the file. To do this press the [Ctrl] button and the letter [O] together then press [Enter].

● WriteOut (save) to a file - Press [Ctrl] and [O] and lastly press [Enter]

ExitingExiting nano can take two forms. The first exits and does not save any changes in the buffer, and the second writes the changes in the buffer to a file and then exits to the command prompt.

● Quit without writing buffer (no save) - Press [Ctrl] and [X] and lastly press [N]● Quit and write out the buffer (save) - Press [Ctrl] and [X] and lastly press [Y]

Information Technology Services - High Performance Computing Group 12 of 12