CS202 Linux Tutorial
đ§
Ian Innes, Robert Lawrence, Caleb Murray, Seth Flanders
August 2024
What is Linux? đĽď¸
Linux is an operating system, which means that it is a collection of underlying software that supports the computerâs basic functions.
The Interface đď¸
Linux uses a command line interface. This interface is in a shell, which acts as an environment for the user to interact with the system. bash, Linuxâs default shell, has its own programming language for the terminal. Users can use bash as a scripting language to string Unix commands together. Command line interface is different from modern day systems such as MacOs and Windows, which use a graphical user interface where the user navigates the computer by using a cursor and icons. For example, to open a document named âdownloadsâ in the command line interface, we would type âcd downloadsâ, whereas with graphical user interface we would click on the file icon named âdownloadsâ.
Command Line Prompt >_
When you access the terminal on your device, you will be greeted with a line of text and a blinking cursor. The text jargon will vary depending on your terminal of choice, but they are (mostly) the same functionality wise.
Graphical User Interface đą
Graphical interfaces differ from the traditional CLI interface used by most Linux operating systems. Rather than using commands to access the contents of the computer, the mouse is used to interact with icons to allow for a simpler and more straightforward user interface.
Commands within the linux operating system đ§
Due to Linux primarily being used with a command-line interface, knowing the commands is of the utmost importance.
- ls
- The command âlsâ lists the contents of the directory the user is currently in.
- A useful option of ls is the -t flag (ls -t) which lists files in order of recently modified.
- mkdir(name)
- Makes a directory inside of the one that you are currently in.
- Want to make multiple ordered directories at once? Add the -p flag to mkdir. (mkdir -p first/second/third)
- pwd
- Prints your current working directory path.
- (child directory name)
- Changes your current directory, based on the one you are already in
- adding ".." to the cd command allows you to go back up your current path. You can add on to this to go back down another path
- Say you are in your "documents" directory: cd ../music would send you back up to the parent directory, and then down into the music directory.
- rm (name)
- Removes a file with the given name. Be careful! Cannot be undone, no recycle bin!
- The -r flag can be added to clear whole directories as well, but the rmdir command is a safer option as it only works on empty directories.
- whoami
Prints the user's username.
- clear
- Clears text from past commands off the screen.
- You can use Ctrl + L as well, but this simply scrolls all the text upwards. You might need it!
- cp (file1 file2)
- Copies the chosen file to another file.
If file2 does not exist, it will create it for you. However, if file2 exists, it will be overwritten!
- mv (file, name or directory)
Move or rename a file. The first name will be the chosen file, then the second will be the new name or directory.
- To differentiate between new name or directory, directories will start with a slash.
- chmod (u g w)
Allows you to change the permissions of a file or a directory.
- You can use ls -l to see the access permissions of different files and directories.
- Chmod uses an octal system to determine permissions. (000, or 0 to 7)
- The first digit determines read ability, second being write, then third being excecute.
- ssh (username@hostname)
Allows the client to remotely connect to another server.
- If you are not connected to the campus wifi (eduroam/utopen), you must use a vpn and connect to the campus system.
- scp (username@remoteMachine:directoryPathToFile localDirectoryPath)
Allows the user to copy files from a remote machine to their local machine, or vice versa.
- Make sure to be careful when getting your local path. You can copy file paths when using file explorer.
Absolute vs. Relative PathđŁď¸
Using the commands seen above, we can use these to create paths to and from directories or documents we might need to access. In Linux a path can be either absolute or relative, hereâs the difference between the two.
- Absolute Path
This is a path to a directory that starts from the root directory. For example if we wanted to access a directory called âdog_photosâ, we would type the following: â/Users/johndoe/Downloads/photos/dog_photosâ. The initial slash denotes the root directory and all absolute paths should begin with that.
- Relative Path
This is a path to a directory that starts from your current directory. For example, if we were in the directory âDownloadsâ and wanted to access âdog_photosâ we would type âcd photos/dog_photosâ.
Vimâ¨ď¸
Vim is an extremely efficient text editor that comes packaged with shortcuts and commands to make the editing experience much easier. Vim minimizes the text editing experience by being key input based (no clicking required) and by having the command line present at all times. A downside to the simplicity is that there is much more memorization required to quickly navigate through the text editor, as compared to other software like Microsoft Word where a GUI is present.
Some useful Vim shortcuts:
- yy (yank)
- Copies the currenty selected line.
- p (put)
- Pastes the current copied line. (Take in mind only lines yanked from Vim can be putted in Vim. Other copied text will need to be pasted with your computerâs context menu (right click))
- dd (delete)
- Cuts the currently selected line. Can be putted after.
- u (undo)
- Undoes what you have done.
- ctrl/cmd + r (redo)
- gg
- Goes to the top of the document.
The command gg can be combined with =G (gg=G) to auto-indent your entire document.
Some useful Vim commands:
- :w (write)
- Writes (saves) your document.
- :q (quit)
- Closes vim, provided you have saved.
- :wq (write and quit)
- Saves your document AND closes Vim. Phenominal.
- :q! (force quit)
- Force close vim, without warnings.
- :sp (split screen)
- Splits off your current view into a seperate window. :q to close the window.
- :(number)
- Goes to the line with that number.
8-28-2024 never doing web design