The command: . ./.short_prompt
executes code inside a file named .short_prompt and sources it (applies all the changes to the current session.) See more details here.
The command: . ./.long_prompt
executes code inside a file named .long_prompt and sources it (applies all the changes to the current session.) See more details here.
The command: pwd
stands for 'print working directory' and shows the current folder in which the terminal is positioned. An example of output from this command is /home/cisc3350/Desktop, which means that the terminal is currently located in the Desktop folder.
The command: whoami
outputs the username of the user that is currently logged into the device/account and are using this terminal. Examples of outputs from this command are miriam, student, admin, or root.
The command: ls
without any additional command-line arguments, stands for 'list' (verb) and shows the contents of the current directory. This includes only the name of the various non-hidden files and folders included in the current folder.
The command: ls -a
(note that the -a is a command-line argument) shows the name of the various files and folders of the current directory, including all the hidden file. A hidden file (or folder) on Linux is one whose name starts with a dot symbol, and examples of hidden files are: . (the link to the current directory [itself!],) .. (the link to the parent directory of the current directory), .bashrc, and the .git folder that might be found in your directory.
The command: ls -l
(note that the -l like 'Larry' is a command-line argument) shows a long printout of the various files and folders of the current directory. In this printout, the information of each file or folder is displayed on a separate line, and includes metadata such as: permissions on using the file, the number of files inside the folder (in case it is a folder,) the username of the user who owns the file, the group of the user who owns the file, the file size in bytes, the recent modification date of the file, and, of course, the name of the file.
The command: ls -al
(or ls -la or ls -a -l or ls -l -a) is a combination of ls -a and ls -l: it shows a long printout of the various files and folders of the current directory, including of all the hidden files.
The command: ls existingDirectory
lists the contents of a directory whose name (or path to) is existingDirectory. You can also add the -a or -l command-line arguments if wanted before or after existingDirectory. Here, existingDirectory could be either a relative or an absolute path to a directory. An absolute path is one that starts with the root directory, like /home/cisc3350/Desktop/, and a relative path is one without the forward slash to its left, like Desktop/games/.
The command: cd
(without any additional command-line arguments) stands for 'change directory'. When typed into the terminal, it will change the current directory of the terminal to your user's home directory. The Linux computer saves the home directories of all the users within the file /etc/passwd, which you can view at any time. To change the home directory to a different one, you should contact the system administrator of your Linux device/account to change it, or, if the machine belongs to you, you can use of the suggested commands at this StackOverflow page to change your home directory to a different one.
The command: cd ..
(note that .. here is a command-line argument) will change the current directory of the terminal to the parent directory of the current folder. For example, if pwd says that the current folder is /home/cisc3350/Desktop/, typing cd .. will change the current directory to /home/cisc3350/. Note that the root directory, / is special. Theoretically, it doesn't have a parent directory, but if you try doing cd .. when inside the root, you will return to ... the root directory itself! So it is like a self-loop.
The command: cd .
will change the current directory of the terminal to the current directory itself! That is, you won't leave the current directory, and cd . serves as a self-loop.
The command: cd ~
just as cd does, will change the current directory of the terminal to your user's home directory.
The command: cd /
will change the current directory of the terminal to the computer's root directory, which is the grandparent of all directories in Linux. Note that we might mention the term 'root' in several contexts: not only do we have a directory called 'root', but we also most likely have a user whose name is root, which is the ultimately-privileged user of the computer who can perform almost any action, including installing new applications, deleting the disk, and accessing files of other users.
The command: cd existingDirectory
will change the current directory of the terminal to the directory indicated by existingDirectory. Here, existingDirectory could be either a relative or an absolute path to a directory. An absolute path is one that starts with the root directory, like /home/cisc3350/Desktop/, and a relative path is one without the forward slash to its left, like Desktop/games/.
The command: mkdir newDirectory
stands for 'make directory' and creates a new directory whose name is newDirectory inside the current directory. For example, if the terminal is currently situated inside /home/cisc3350/Desktop/, and you type mkdir games, a new folder called games will be created inside the Desktop/ directory (in case it is not present there already; if so, an error message that tells that the directory already exists will be displayed to the terminal.)
The command: touch newFile
does the following: if the file named newFile already exists in the current directory, its recently modified date will be updated to now. Otherwise, if a file with such a name does not exist, the touch will create an empty file called newFile in the current directory. For example, typing touch notes.txt will create an empty text file called notes inside the current directory (in case this file doesn't already exist there.)
The command: rmdir existingDirectory
stands for 'remove directory' and will delete the folder named ExistingFolder located inside the current directory. If the existingDirectory directory contains any files, or if the directory doesn't exist, an error message will be printed to the terminal. In case you wish to erase a non-empty directory, first delete the files inside the directory, and then rmdir the directory itself.
The command: rm existingFile
stands for 'remove' and will delete the file named existingFile located inside the current directory. If the existingFile doesn't exist, an error message will be printed to the terminal. An example would be rm myfile.txt, using which we can delete a file called myfile.txt inside the current directory. Note that, after a file is deleted, it is permanently erased from the computer, unlike files that are deleted on a Windows or a Mac. A GUI version of Linux might feature a 'garbage bin' that termporarily stores deleted files, but the command-line version doesn't have such a feature by default.
The command: cat existingFile
stands for 'concatenate' and will output the contents of the file named existingFile located inside the current directory to the terminal's window. You can't edit the contents of existingFile using cat, but you can see the file full content, regardless of how large the file is. Once the content of existingFile is output, the command prompt (e.g., student@student:~/Desktop$, which is the line in Linux that awaits your commands) will return back to you to get further commands from you. The reason that the command is called 'concatenate' is that it can actually take the names of several files and print them to the screen, one after the other, which resembles the concatenation of files. An example of using cat with a single file is by typing cat myfile.txt, which will show the contents of myfile.txt on the screen.
The command: clear
brings the command prompt (e.g., student@student:~/Desktop$, which is the line in Linux that awaits your commands) to the top of the terminal in a way that is similar to 'clearing' the commands and data that were previously output to the screen. After typing entering this command, there is going to be nothing on the screen besides the command prompt.
The command: cp path/To/ExistingFile path/To/The/Newly/CreatedCopyFile
stands for 'copy' and creates a copy of the file that is found in the directory path/To/ called ExistingFile in the destination directory path/To/The/Newly/ under the name CreatedCopyFile. That is, the original file ExistingFile remains unchanged, and we just create a 'clone' of this file inside a different folder (and, possibly, with a new name.)
The command: mv path/To/ExistingFile path/To/The/Newly/CreatedCopyFile
stands for 'move' and performs two actions: (1) it creates a copy of the file ExistingFile that is found in the directory path/To/ and pastes it in the directory path/To/The/Newly/ under the name CreatedCopyFile (2) afterwards, it deletes the original file ExistingFile from the path/To/ directory. This is essentially the action of 'moving' a file from one place to another, especially if you name the new file with the name of the original one.
The command: sudo someCommand
stands for 'super user do' and lets you execute the command someCommand with elevated privleges. The reason that the execution of some commands, such a those that install a new program, require the call to sudo is that these actions are considered sensitive and might bring some danger to the computer if done incorrectly. As such, not all users are permitted to perform such actions. One way to perform such an action is by calling sudo, which temporarily elevates the user's privileges to those of the 'super user'. However, not all users can use the sudo command: for some of you, typing sudo will result in a error message like: "user x is not on the sudoers list", which means that you can't request to elevate your privleges to perform that action. In such a case, if the action is necessary, the user should contact the system administrator and request that they add the user to the sudoers list, if the organization/institution allows. An example of using sudo is typing sudo apt-get update, which updates all the installed software on the Linux device to the latest versions.
Important Note: If you are a regular/unprivileged Linux user (for example, if you are using your Brooklyn College Linux Account,) you might have no permission to use the sudo command, as explained in the paragraph above. No homework assignment or exam will ask you to use the sudo command, so don't worry about this current inability to use sudo. If you have access to a Linux virtual machine in which you are an administrator user, you should be able to use sudo.
The command: su
stands for 'super user' and elevates your user privleges until you exit the super user mode with the Linux exit command. If, when typing this command, you receive an error message like: su: Authentication failure but you know that your user is on the sudoers list, you might instead type the command sudo -i below. If you aren't on the sudoers list, you can't use su.
The command: sudo -i
is an alternative to typing su and elevates your user privleges until you exit the super user mode with the Linux exit command. In many cases, the computer's super user is the user whose name is root, so you actually switch to the root's account by entering sudo -i. One quick way to recognize that you are in 'super user mode' is to note that the symbol at the end of the command prompt is the number sign, #, and not the dollar sign, $.
The command: man someCommand
stands for 'manual' and opens the manual page for the Linux command someCommand. For example, entering man cp will show the manual page for the 'copy' command. A manual page includes the description of the command, the list of arguments that the command accepts, and any other essential details for the use of the command. If the manual page is longer than the screen, you can scroll down by pressing and holding the down arrow of your keyboard. To exit the manual page and return to the terminal, press the key 'Q' (stands for 'quit') at any time.
The command: info someCommand
opens an information page for the Linux command someCommand, which usually contains more information, usage recommendations, and examples about the command than the manual page for this command does. For example, entering info cp will show the information page for the 'copy' command. You can navigate an information page in the same way as you do a manual page, by using the arrow keys (to move up and down the page) and the 'Q' key to quit the page.
The command: ping serverName
stands for 'Packet Internet Groper' and checks if the server (essentially, a remote device or webpage) whose name, link, or IP address is serverName is responsive over a network, like the Internet. For instance, typing ping www.google.com will initiate a connection with the Google website; if the connection is successful, your Linux device and Google will start exchanging data. Otherwise, the data that your Linux device sends won't be 'answered' by Google. This exchange of data will continue endlessly, so you need to press Ctrl + C to finish the exchange and return the command prompt back to you. After you press Ctrl + C, the overall data exchange statistics will be displayed on the terminal before the prompt is returned to you.
A different purpose for using the ping command is to check if your device is connected to the Internet. For example, since Google is 'up and running' at all times, getting an error message after entering ping www.google.com means that the Linux device is not connected to the Internet (since the connection error is not Google's fault.)
The command: wget someRemoteFile
stands for 'web get' and copies over a file whose URL is someRemoteFile from a remote server (e.g., a website). This file could be anything, including text files, Word files, C source files, and even HTML pages (webpages). After this command runs, if the output says that "file such and such saved", it means that the file was successfully copies to the current directory where the terminal is located. Otherwise, either the file doesn't exist, a bad URL was typed, or there is no Internet connection. Another possibility is that the wget program is not installed on your device, in which case you could install it on your device (if you know you have permissions to use the sudo command) by typing sudo apt-get update followed by sudo apt-get install wget and then following the installation commands on the screen.
The command: grep "pattern" existingDirectory
stands for 'global regular expression print' and output the names of the file where pattern, which is either a simply search string or some regular expression, is present within the existingDirectory folder. For example, entering grep "Bla Bla!" * will show all the files in the current directory where the string Bla Bla! is present. This is because the * symbol is a 'wild-card' that selects all the files in the current directory for this search. The grep command has many useful command-line options, which you can learn more about in the man grep or info grep manual pages.
The command: gcc -Wall -Wextra -O2 -g -o program program.c
compiles the C source code located inside the file program.c. See more details here.
The command: ./executableFile
executes (runs) a program whose name is executableFile and that is located in the current directory using the terminal. The output that this program produces will be displayed in the terminal. In our class, we will be creating and running C programs after we compile them. For example, entering ./prog1 will run the program/application called prog1 that is located within the current directory, and entering ./a.out will run the program/application called a.out that is located within the current directory. You may, in a similar way, run programs that are located in other directories on your device/account by replacing the dot . with the path to the folder where that program that you are trying to run resides. For example, if a program called my_app is located in the folder /home/cisc3350/Desktop, you can execute it by typing: /home/cisc3350/Desktop/my_app in the terminal and then pressing ENTER/RETURN.
The command: gdb ./executableFile
runs the GNU C Debugger software whose purpose is to run the program located in the current directory whose name is executableFile and trace/debug this program. Once you enter this command, you will enter the debugger's menu. To start running the program, type run. If an error occurs during the execution, the debugger will pause the execution and show what the error is and where (inside which function and on which line) it happened. You can then type the backtrace (or bt, in short) command to show the sequence of function calls starting from the main function that describes how this faulty statement was reached. To exit the debugger app, press 'Q'. The manual page of gdb features the full list of commands that you can use within the debugger, such as printing the values stored in variable, creating breakpoints, and other useful commands that you can use to find bugs faster!
The command: exit
closes the terminal window. This is an alternative to clicking the 'X' button at the top corner of the terminal application window.
The command: vim someFile
either creates an empty file named someFile within the current directory (if a file under this name doesn't exist yet) using the vim command-line text editor, or opens an existing file named someFile. Within the vim editor, you can change, delete, and add content. You can find several internet guides and tutorials on vim on our Blackboard page under Textbook & Guides > Guides > "Text Editors -- Tutorials + YouTube + Cheat Sheets".
The command: emacs someFile
either creates an empty file named someFile within the current directory (if a file under this name doesn't exist yet) using the emacs command-line text editor, or opens an existing file named someFile. Within the emacs editor, you can change, delete, and add content. You can find several internet guides and tutorials on emacs on our Blackboard page under Textbook & Guides > Guides > "Text Editors -- Tutorials + YouTube + Cheat Sheets".
The command: nano someFile
either creates an empty file named someFile within the current directory (if a file under this name doesn't exist yet) using the nano command-line text editor, or opens an existing file named someFile. Within the nano editor, you can change, delete, and add content. You can find several internet guides and tutorials on nano on our Blackboard page under Textbook & Guides > Guides > "Text Editors -- Tutorials + YouTube + Cheat Sheets".