Level 1 Linux Exercises
Level 1 Background Information
Linux Quick Reference
mkdir
– to organize files and directories. This will make a new directory:
mkdir CS_Programs
cd
– change into another directory:- To change into a specific directory:
cd CS_Programs
- To change into a directory using a wild card:
cd CS*
- To change back to the directory above:
cd ..
- To change to the root directory (regardless):
cd
- To change into a specific directory:
ls
– list directory contents:- To list the contents of the current directory:
ls
- To list the contents of specific files (e.g., that start with a capital P):
ls P*
- To list the contents of a specific directory:
ls CS_Programs
- To list the contents of directories using a wild card:
ls CS*
- Add flags to get more detailed displayed:
ls -l /etc
- Use the wildcard (*) to list all of the .cpp files in the current directory:
ls *.cpp
- To list the contents of the current directory:
cat
– to display the contents of a file:cat test1.cpp
pwd
– to determine your current path and directory name :pwd
cp
– copy a file or directory:- For example:
cp source dest
if you want to copy a directory use the -R option for recursive. The forward slash (in front of the path) means that we are working from the root directory:cp -R ./source ./dest
- The source and destinations may be complete paths or a path from the current directory; the following will copy the entire CS_Programs directory and all of its files into the CS_Copy directory:
mkdir CS_Copy
cp -R CS_Programs CS_Copy
- For example:
mv
– move a file or directory. You could think of this as a rename but it can also move a file to another directory! Make sure to pay close attention to the order of the arguments. The first argument (source) is the file or directory that you want to copy from and the second argument (dest) is the file that you want to copy to (e.g., the file to be created). Keep in mind that a move does not leave the original (unlike copy) so use it with great caution!- Syntax:
mv source dest
- Move a file:
mv program1.cpp new_name.cpp
- Rename a directory:
mv CS_Programs new_directory_name
- Syntax: