Podcast
Questions and Answers
Which component is the lowest level of user-mode software that allows users to start other programs?
Which component is the lowest level of user-mode software that allows users to start other programs?
- Operating System
- User Interface Program (Shell/GUI) (correct)
- Hardware
- Kernel
What role does the 'command interpreter' or 'shell' play in the command line environment?
What role does the 'command interpreter' or 'shell' play in the command line environment?
- It compiles user programs into executable code.
- It reads and interprets commands from a terminal. (correct)
- It directly interacts with the kernel to allocate memory.
- It manages the hardware resources of the system.
After a user types a command like date
in the shell, what is the shell's immediate next action?
After a user types a command like date
in the shell, what is the shell's immediate next action?
- The shell creates a child process to run the `date` program. (correct)
- The shell terminates itself.
- The shell directly executes the `date` command without creating a new process.
- The shell updates its internal configuration files.
What character typically indicates that the shell is ready to accept a command?
What character typically indicates that the shell is ready to accept a command?
By default, which type of files or directories does the ls
command NOT display?
By default, which type of files or directories does the ls
command NOT display?
Which ls
option displays all files, including hidden files?
Which ls
option displays all files, including hidden files?
To display files in the order of most recently modified to least recently modified, which ls
option should be used?
To display files in the order of most recently modified to least recently modified, which ls
option should be used?
How do you represent spaces in filenames when using the ls
command?
How do you represent spaces in filenames when using the ls
command?
Which command allows you to browse through a text file, advancing one page at a time using the Spacebar?
Which command allows you to browse through a text file, advancing one page at a time using the Spacebar?
Which command is like more
, but also allows backward movement and pattern searches within the file?
Which command is like more
, but also allows backward movement and pattern searches within the file?
Which command displays only the beginning portion of a file?
Which command displays only the beginning portion of a file?
Which command would you use to sort the contents of a file?
Which command would you use to sort the contents of a file?
Which command displays the differences between two files in a side-by-side format, highlighting the discrepancies?
Which command displays the differences between two files in a side-by-side format, highlighting the discrepancies?
How can you redirect the standard output of a command to a file, overwriting the file if it already exists?
How can you redirect the standard output of a command to a file, overwriting the file if it already exists?
What does the >>
operator do when redirecting output to a file?
What does the >>
operator do when redirecting output to a file?
How can you use a file as standard input for a command?
How can you use a file as standard input for a command?
What is the file descriptor number assigned to standard error?
What is the file descriptor number assigned to standard error?
If you want to discard the error messages from a command and not display them, what redirection should you use?
If you want to discard the error messages from a command and not display them, what redirection should you use?
What is a 'pipe' in the context of command-line operations?
What is a 'pipe' in the context of command-line operations?
How do you connect the output of one command to the input of another command using a pipe?
How do you connect the output of one command to the input of another command using a pipe?
Which command clears the terminal screen?
Which command clears the terminal screen?
What command shows the available disk space on the system?
What command shows the available disk space on the system?
What command displays the amount of free memory on the system?
What command displays the amount of free memory on the system?
In UNIX file permission codes, what does 'rwx' represent?
In UNIX file permission codes, what does 'rwx' represent?
In the context of directory permissions, what does 'x' indicate?
In the context of directory permissions, what does 'x' indicate?
How can you view the permission settings for a file in the command line?
How can you view the permission settings for a file in the command line?
What command is used to change the permissions of a file or directory?
What command is used to change the permissions of a file or directory?
If you want to add write permission for the group to a file named myfile.txt
, which command would you use?
If you want to add write permission for the group to a file named myfile.txt
, which command would you use?
What is the effect of the command chmod a=
on a file?
What is the effect of the command chmod a=
on a file?
In the context of command-line wildcards, what does the asterisk (*) represent?
In the context of command-line wildcards, what does the asterisk (*) represent?
What is a symbolic link (symlink)?
What is a symbolic link (symlink)?
What is the purpose of the pwd
command?
What is the purpose of the pwd
command?
How do you navigate to the parent directory in the command line?
How do you navigate to the parent directory in the command line?
What command creates a new directory?
What command creates a new directory?
What command creates a new, empty file?
What command creates a new, empty file?
What command is used to rename a file or directory?
What command is used to rename a file or directory?
Which command is used to copy files?
Which command is used to copy files?
How do you remove a non-empty directory using the command line?
How do you remove a non-empty directory using the command line?
Which command is used to locate files or directories on a Linux system based on various criteria?
Which command is used to locate files or directories on a Linux system based on various criteria?
What is an environment variable?
What is an environment variable?
Which command is used to display all the environment variables?
Which command is used to display all the environment variables?
Which environment variable typically stores the user's home directory?
Which environment variable typically stores the user's home directory?
What command lists the currently running processes?
What command lists the currently running processes?
What command is used to terminate a process, given its PID?
What command is used to terminate a process, given its PID?
Flashcards
Command interpreter/Shell
Command interpreter/Shell
A program that reads commands from a terminal.
Prompt
Prompt
A character or symbol indicating the shell is ready.
ls Command
ls Command
Lists files in current directory (or specified directory).
ls --help Command
ls --help Command
Signup and view all the flashcards
ls -a Command
ls -a Command
Signup and view all the flashcards
ls -t Command
ls -t Command
Signup and view all the flashcards
cat Command
cat Command
Signup and view all the flashcards
more Command
more Command
Signup and view all the flashcards
less Command
less Command
Signup and view all the flashcards
head Command
head Command
Signup and view all the flashcards
tail Command
tail Command
Signup and view all the flashcards
sort Command
sort Command
Signup and view all the flashcards
diff Command
diff Command
Signup and view all the flashcards
sdiff Command
sdiff Command
Signup and view all the flashcards
Operator
Operator
Signup and view all the flashcards
Operator
Operator
Signup and view all the flashcards
< Operator
< Operator
Signup and view all the flashcards
Pipe (|)
Pipe (|)
Signup and view all the flashcards
clear Command
clear Command
Signup and view all the flashcards
df Command
df Command
Signup and view all the flashcards
free Command
free Command
Signup and view all the flashcards
ls -l Command
ls -l Command
Signup and view all the flashcards
chmod Command
chmod Command
Signup and view all the flashcards
Asterisk (*)
Asterisk (*)
Signup and view all the flashcards
Question Mark (?)
Question Mark (?)
Signup and view all the flashcards
Symbolic Link (symlink)
Symbolic Link (symlink)
Signup and view all the flashcards
pwd Command
pwd Command
Signup and view all the flashcards
cd Command
cd Command
Signup and view all the flashcards
cd .. Command
cd .. Command
Signup and view all the flashcards
cd ~ Command
cd ~ Command
Signup and view all the flashcards
mkdir Command
mkdir Command
Signup and view all the flashcards
touch command
touch command
Signup and view all the flashcards
mv Command
mv Command
Signup and view all the flashcards
cp Command
cp Command
Signup and view all the flashcards
rmdir Command
rmdir Command
Signup and view all the flashcards
rm -rf Command
rm -rf Command
Signup and view all the flashcards
find command
find command
Signup and view all the flashcards
man Command
man Command
Signup and view all the flashcards
env Command
env Command
Signup and view all the flashcards
ps
ps
Signup and view all the flashcards
Study Notes
Command Line Basics
- The user interface program (shell or GUI) is the lowest level of user-mode software.
- This level allows users to start other programs like web browsers or music players.
Command Interpreter (Shell)
- A process called the command interpreter or shell reads commands from a terminal.
- Once a user types a command (e.g., requesting program compilation), the shell creates a new process to run the compiler.
- After the compilation finishes, the process executes a system call to terminate itself.
Shell Input and Output
- The shell uses the terminal as standard input/output.
- It displays a
prompt
(e.g., a dollar sign) to indicate it's ready for commands. - For instance, when a user types
date
, the shell creates a child process to run the date program. - The shell waits for the child process to terminate.
- After the child process finishes, the shell displays the prompt again to read the next input line.
Recommended Resources
- Free command line course: https://www.codecademy.com/learn/learn-the-command-line
- Command line videos: https://www.youtube.com/playlist?list=PLW5y1tjAOzI2ZYTlMdGzCV8AJuoqW5lKB
- Jason Cannon's "Linux Succinctly" (2014).
- Jason Cannon's "Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners" (2014).
- Online command line tutorials at tutorialspoint.com: https://www.tutorialspoint.com/unix_terminal_online.php
Basic Commands
ls
: Lists files in the current directory.ls --help
: Displays help information on the use of thels
command.ls /home
: Lists files in the/home
directory.ls /
: Lists files in the root directory.ls Documents/ Downloads/
: Lists the contents of theDocuments
andDownloads
directories.
ls Command Options
- By default,
ls
does not show files or directories starting with a period, as they are considered hidden in Linux. ls -a
: Displays all files, including hidden ones.ls -t
: Sorts the output of thels
command by time, showing the most recently modified items first.ls -rt
: Sorts the output of thels
command by time in reverse order.
Filenames with Spaces
ls -l 'my to do list.txt'
orls -l my\ to\ do\ list.txt
: Correctly lists files with spaces in their names.
File Content Commands
cat
: Concatenates or displays files.more
: Allows browsing through a text file.- Press Spacebar to advance to the next page.
- Press Enter to advance to the next line.
- Type
q
to quit viewing the file.
less
: Similar tomore
, but allows backward movement and pattern searches.head
: Displays the beginning portion of a file.tail
: Displays the ending portion of a file.
Sorting and Comparing Files
diff
: Displays the differences between files.sdiff
: Displays two files side-by-side, highlighting the differences.
Standard Input/Output Redirection
date > date.txt
: Redirects standard output to a file nameddate.txt
.>>
: Used to append output to a file.sort < fruits.txt
: Standard input is redirected.sort < fruits.txt > outfile.txt
ls info.txt nofile.txt 2> errors.txt
:ls info.txt nofile.txt 1> out.txt 2> errors.txt
:ls info.txt nofile.txt > out.txt 2>&1
: Redirects one file descriptor to another.ls info.txt nofile.txt 2> /dev/null
: Redirects output to the null device, preventing it from displaying or saving.
Pipes
- A pipe is a pseudofile that connects two processes.
- Processes communicate through a pipe.
- Process A writes data to process B.
- Process B reads data in UNIX, like ordinary file reads/writes.
cat fruits.txt vegetables.txt | sort
: Connectscat
andsort
with a pipe.cat fruits.txt vegetables.txt | sort > out.txt
: Connectscat
andsort
with a pipe that redirects to out.txt
Screen, Disk Space, and Memory Commands
clear
: Clears the contents of the screen.cat fruits.txt \ vegetables.txt | sort > out.txt
:df
: Shows available disk space.free
: Shows the amount of free memory.
File Permissions
- Before reading or writing a file, it must be opened, and permissions are checked.
- UNIX protects files with a 9-bit binary protection code.
- The code contains three 3-bit fields.
- Owner.
- Owner's group.
- Everyone else.
- Each has read, write, and execute access bits.
- The three bits are known as rwx bits
- Example:
rwxr-x--x
- The owner can read/write/execute the file.
- Group members can read/execute.
- Everyone else can execute.
- For a directory,
x
gives search permission. - A dash means that the permission is absent.
ls -l
: Shows permission settings for a file.
File Type
- First character is the type of the file.
Changing Permissions
- Permissions are also known as modes.
chmod
(change mode) changes permissions.chmod g+w somefile.txt
: Adds write permission for the group.chmod g-w somefile.txt
: Removes write permission for the group.chmod g+wx somefile.txt
: Adds write and execute permissions for the group.chmod ug+wx somefile.txt
: Adds write and execute permissions for the user and group.chmod u=rwx,g+x somefile.txt
: Sets read, write, and execute permissions for the file owner and adds execute permission for the group.chmod a=r somefile.txt
: Sets the file to be readable by everyone.- The equal sign (=) replaces current permissions.
chmod a=r,a=w somefile.txt
produces different results tochmod a=w,a=r somefile.txt
chmod a= somefile.txt
: Removes permissions following the equal sign.
Wildcards
ls m*
: Lists files starting withm
.ls *.txt
: Lists files with.txt
extension.- The asterisk matches anything, while the question mark matches a single character.
ls ??????.txt
Symbolic Links (Symlinks)
- A symlink points to an actual file or directory.
- The symlink acts as a pointer.
- Symbolic links create shortcuts to long names or paths.
- Another common use for symlinks helps point to an application's current version.
Working Directory
- Each process at every instance has a current working directory.
- Path names not beginning with a slash are looked for.
pwd
: Print working directory- System call changes working directory using the:
cd /usr/share/doc
- Change directory (absolute path):
cd doc
- Go to parent directory:
cd ..
- Go home:
cd ~
- The tilde represents the current user's home directory
Directory and File Manipulation
mkdir test
: Creates a directory calledtest
.cd test
: Navigates to thetest
directory.touch newfile.txt
: Creates a new empty file.mv newfile.txt ..
: Moves or renames file or directories to the parent directory.mv newfile.txt test
: Moves file back to the directorytest
.ls test
: Checks that the file is back in the directorytest
.mv newfile.txt mynewfile.txt
: Renames the file.mv test mydir
: Renames the directory.cp mynewfile.txt myoldfile.txt
: Copies files.cp info.txt Documents
: Copiesinfo.txt
into theDocuments
directory.
Directory Operations
cp -a mydir Documents
: Copies a whole directory.rmdir mydir
: Removes an empty directory.rm -rf mydir
: Removes a non-empty directory.
Finding Files
find /etc -name l*
: example of finding files
Find Command
- Locates files or directories on a Linux system.
Man Pages
- The
man
command: displays the online manual for a given command.
Environment Variables
- An environment variable is a name-value pair.
- Programs determine their actions.
env
: To display all the environment variables
Processes
ps
: To Lists the currently running processes.ps -e | less
: To see every process running on the system.kill 2994
: To kill the process, using it's PID.kill -9 2994
: Kills the process if it's still running.
Superuser
su
: Become the superuser.su -c pwd
: Execute a command as a superuser.su -c 'ls -l /'
: Quoted command to execute if the command is more than one word in length.whoami
: To show what user you are currently working as
Sudo Command
- Allows you to run a command with the security privileges of another user.
- Sudo uses the superuser in no username is specified.
sudo ls
: example to "runls
as root user".sudo -l
: List commands to execute with sudosudo -u someuser command
: Allows you to Run command as another usersudo su
: Switch to the superuser account
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.