1.11 – Linux - Linux Commands

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What is the primary reason that commands used in Linux are often the same as those used in macOS?

  • Both operating systems are derived from the same Unix foundation. (correct)
  • Linux was originally developed as a clone of macOS.
  • Commands are standardized by the IEEE and must be consistent across all OSs.
  • macOS is designed to directly emulate a Linux environment for application compatibility.

If you need to find out more about the diff command, which command do you use to access the manual?

  • `info diff`
  • `man diff` (correct)
  • `help diff`
  • `diff --help`

What command is used in Linux to list the contents of a directory?

  • dir
  • ls (correct)
  • list
  • show

You need to view a long listing of files in a directory one page at a time. Which command would you use?

<p>ls -l | more (C)</p> Signup and view all the answers

Which command displays the current directory you are working in?

<p>pwd (A)</p> Signup and view all the answers

What command would you use to rename notes.txt to important_notes.txt?

<p>mv notes.txt important_notes.txt (D)</p> Signup and view all the answers

To create a copy of report.pdf named report_backup.pdf, which command should you use?

<p>cp report.pdf report_backup.pdf (C)</p> Signup and view all the answers

How can you remove a file named temp.log in Linux?

<p>rm temp.log (A)</p> Signup and view all the answers

In Linux, what does the 'x' permission signify for a file?

<p>The file can be executed. (A)</p> Signup and view all the answers

What does the command chmod 750 file.txt do?

<p>Gives the owner all permissions, the group read and execute permissions, and others no permissions. (B)</p> Signup and view all the answers

Which command removes write permissions for all users from the file data.txt?

<p>chmod a-w data.txt (B)</p> Signup and view all the answers

What command changes the owner of report.txt to a user named 'accounting'?

<p>chown accounting report.txt (C)</p> Signup and view all the answers

Why is the sudo command used in Linux?

<p>To run commands with superuser privileges. (A)</p> Signup and view all the answers

If you want to start a terminal session as the superuser, which command should you use?

<p>su (D)</p> Signup and view all the answers

Which command is commonly used on Debian-based Linux distributions to install new software packages?

<p>apt-get (D)</p> Signup and view all the answers

You are using a Red Hat-based Linux distribution. Which command would you typically use to install a software package?

<p>yum (D)</p> Signup and view all the answers

To view the IP address and other network configuration details in Linux, which command is most appropriate?

<p>ip address (C)</p> Signup and view all the answers

Which command displays the amount of free disk space on your Linux system in a human-readable format?

<p>df -h (B)</p> Signup and view all the answers

You need to search for the word 'error' within a log file named system.log. Which command would you use?

<p>grep error system.log (B)</p> Signup and view all the answers

To view all currently running processes for all users on a Linux system, which command should you use?

<p>ps -e (A)</p> Signup and view all the answers

Which command provides a dynamic, real-time view of the processes running on a Linux system, including CPU and memory usage?

<p>top (B)</p> Signup and view all the answers

You are trying to locate a configuration file named settings.conf within your current directory and all its subdirectories. Which command would you use?

<p>find . -name settings.conf (B)</p> Signup and view all the answers

What is the purpose of the dig command in Linux?

<p>To perform DNS lookups. (D)</p> Signup and view all the answers

Which Linux command is used to combine multiple files into a single file?

<p>cat (B)</p> Signup and view all the answers

You have two files, part1.txt and part2.txt, and you want to combine them into a new file called full.txt. Which command accomplishes this?

<p>cat part1.txt part2.txt &gt; full.txt (B)</p> Signup and view all the answers

Which command-line text editor is commonly included in many Linux distributions and known for its simplicity?

<p>nano (B)</p> Signup and view all the answers

When using the nano editor, which key combination is used to save the current file?

<p>Ctrl+O (D)</p> Signup and view all the answers

You have just finished editing a file in nano. Which key combination will exit the editor?

<p>Ctrl+X (C)</p> Signup and view all the answers

What is the likely outcome of running the command mv file1.txt /opt/?

<p>It moves file1.txt to the /opt/ directory. (A)</p> Signup and view all the answers

Which command would correctly display the processes that are owned by the user 'sarah'?

<p>ps -u sarah (D)</p> Signup and view all the answers

A file has permissions rwxr-xr--. What permissions does the 'group' have on this file?

<p>Read and execute (D)</p> Signup and view all the answers

What command would you use to display the contents of a file named config.ini in the terminal?

<p>cat config.ini (B)</p> Signup and view all the answers

Which command can be used to determine the external IP address of your Linux system from the command line?

<p>curl ifconfig.me (D)</p> Signup and view all the answers

You want to find all files in the /var/log directory that are larger than 10MB. Which command would accomplish this?

<p>find /var/log -size +10M (B)</p> Signup and view all the answers

What command is used to view the routing table on a Linux system?

<p>route (D)</p> Signup and view all the answers

You need to kill a process with a PID of 1234. Which command will achieve this?

<p>kill 1234 (D)</p> Signup and view all the answers

How can you count the number of lines in a file named document.txt?

<p>wc -l document.txt (B)</p> Signup and view all the answers

What command is used to display the last lines of a file?

<p>tail (A)</p> Signup and view all the answers

What is the significance of the man command in Linux?

<p>It provides access to the system's reference manuals for commands and utilities. (C)</p> Signup and view all the answers

When using the ls -l command, what type of information is provided about each file?

<p>File name, size, modification date, permissions, owner, and group. (B)</p> Signup and view all the answers

When using ls -l | more, what does the pipe (|) accomplish?

<p>It redirects the output of <code>ls -l</code> to the <code>more</code> command, displaying it one page at a time. (B)</p> Signup and view all the answers

What is the main function of the pwd command?

<p>Prints the absolute path of the current working directory. (D)</p> Signup and view all the answers

What is the primary function of the mv command?

<p>To move or rename files and directories. (D)</p> Signup and view all the answers

What is the function of the cp command?

<p>Create a copy of a file or directory. (D)</p> Signup and view all the answers

Before removing a directory with rm, what must you ensure?

<p>The directory is empty. (B)</p> Signup and view all the answers

In the context of file permissions, what does the 'w' signify?

<p>Write permission. (C)</p> Signup and view all the answers

If a file's permissions are represented as rwxr-x---, what permissions are granted to the 'group'?

<p>Read and execute only (A)</p> Signup and view all the answers

What is the purpose of the chmod command?

<p>Modify file permissions. (B)</p> Signup and view all the answers

What is the effect of the command chmod a-w file.txt?

<p>It removes write permissions for all users from the file. (A)</p> Signup and view all the answers

Why is it necessary to use sudo before the chown command in most cases?

<p>To execute the command with administrator privileges. (B)</p> Signup and view all the answers

What does the command su do without any arguments?

<p>It switches the current user to the superuser (root). (B)</p> Signup and view all the answers

What is the purpose of apt-get?

<p>A package management system used to install, update, or remove software. (B)</p> Signup and view all the answers

On a Red Hat-based system, what is the equivalent command to apt-get?

<p>yum (A)</p> Signup and view all the answers

What specific information does the command ip address provide?

<p>The system's IP addresses, subnet masks, and interface details. (C)</p> Signup and view all the answers

How does using the -h option with the df command change the output?

<p>It shows the output in a human-readable format (e.g., KB, MB, GB). (C)</p> Signup and view all the answers

What is the primary use of the grep command?

<p>To search for specific text patterns in files. (B)</p> Signup and view all the answers

What is the difference between ps and ps -e?

<p><code>ps</code> shows processes owned by the current user, while <code>ps -e</code> shows all processes on the system. (A)</p> Signup and view all the answers

How can you stop the output of ps -e | more and return to the command prompt?

<p>Press the 'q' key. (D)</p> Signup and view all the answers

What is the primary advantage of using the top command over ps?

<p><code>top</code> provides a dynamic, real-time view of processes and system resource usage. (D)</p> Signup and view all the answers

What do the three numbers displayed as 'load average' in the top command represent?

<p>The average number of processes waiting to run over the last 1, 5, and 15 minutes. (B)</p> Signup and view all the answers

While using the top command, what key would you press to terminate a process?

<p>k (A)</p> Signup and view all the answers

What is the primary purpose of the find command?

<p>To locate files and directories based on specified criteria. (D)</p> Signup and view all the answers

In the find command, what does the '.' signify as the starting point for the search?

<p>The current working directory. (D)</p> Signup and view all the answers

What does the > symbol do in the command cat file1.txt file2.txt > combined.txt?

<p>It redirects the combined output of <code>file1.txt</code> and <code>file2.txt</code> into <code>combined.txt</code>. (B)</p> Signup and view all the answers

What is the main purpose of the nano command?

<p>A command-line text editor. (C)</p> Signup and view all the answers

In nano, which key combination saves the current file?

<p>Ctrl+O (C)</p> Signup and view all the answers

What command would you use to exit the nano editor?

<p>Ctrl+X (A)</p> Signup and view all the answers

Flashcards

What is a Terminal in Linux?

A program that allows users to interact with the Linux operating system by typing commands. Examples include Terminal and XTerm.

What is the 'ls' command?

A Linux command that lists the contents of a directory, including files, directories, and symbolic links. Similar to the 'dir' command in Windows.

What is the 'ls -l' command?

An option used with the 'ls' command to display a detailed, long-form listing of directory contents, including permissions, owner, size, and modification date.

What is the 'more' command?

A command used to display the output of another command one page at a time, preventing it from scrolling off the screen. It is used with a pipe.

Signup and view all the flashcards

What is the 'pwd' command?

A command that displays the current directory path. It helps users identify their location in the file system, especially when working with multiple windows or remote systems.

Signup and view all the flashcards

What is the 'mv' command?

A command used to rename files or directories. It can also move files from one directory to another.

Signup and view all the flashcards

What is the 'cp' command?

A command used to create a copy of a file or directory. The syntax is cp [source] [destination].

Signup and view all the flashcards

What is the 'rm' command?

A command used to remove files or directories. For directories, they must be empty before using rm.

Signup and view all the flashcards

What do 'r', 'w', and 'x' stand for in file permissions?

r = read access, w = write access, x = execute access. These define how files can be used by different users.

Signup and view all the flashcards

What is the 'chmod' command?

A command used to change the permissions (or mode) of a file or directory. It uses numeric or symbolic modes to set read, write, and execute permissions for user, group, and others.

Signup and view all the flashcards

What is the 'chown' command?

A command used to change the owner and/or group associated with a file or directory. It often requires superuser privileges (sudo).

Signup and view all the flashcards

What is the 'sudo' command?

A command used to execute another command with superuser (administrator) privileges. It allows users to perform tasks that require elevated permissions.

Signup and view all the flashcards

What is the 'apt-get' command?

A command line tool used on some Linux distributions (like Ubuntu) to manage software packages. It can install, update, or remove software.

Signup and view all the flashcards

What is the 'yum' command?

A command line tool used on Red Hat-based Linux distributions to manage software packages. It can install, update, or remove software in RPM format.

Signup and view all the flashcards

What is the 'ip' command?

A command used to display or configure network interfaces and routing tables. ip address shows current config, ip route displays routing table.

Signup and view all the flashcards

What is the 'df' command?

A command used to display the amount of disk space available on the file systems.

Signup and view all the flashcards

What is the 'grep' command?

Finds text within a file.

Signup and view all the flashcards

What is the 'ps' command?

A command that displays a snapshot of the current processes.

Signup and view all the flashcards

What is the 'top' command?

A command that provides a real-time view of the running processes. Sorted by CPU usage, memory and more.

Signup and view all the flashcards

What is the 'find' command?

Finds files by name and extension.

Signup and view all the flashcards

What is the 'dig' command?

Queries DNS name servers to retrieve domain name information such as IP addresses.

Signup and view all the flashcards

What is the 'cat' command?

Concatenates the contents of multiple files into one output.

Signup and view all the flashcards

What is the 'nano' command?

Edits text files.

Signup and view all the flashcards

Study Notes

  • These notes cover essential Linux commands for command-line interaction, file management, permissions, user management, package management, and network configuration.
  • macOS is derived from Unix, like Linux, resulting in command similarities.
  • Commands in this summary can be tried on a live CD version or a virtual machine with Linux installed.
  • The man command provides detailed information on command syntax (e.g., man grep).

Listing Directory Contents

  • ls lists files, directories, and symbolic links; color-codes items in some versions.
  • ls -l provides a longer, more detailed listing including permissions, owner, group, size, and modification date.
  • ls -l | more limits output to one page at a time for easier viewing.
  • pwd (Print Working Directory) displays the current directory path.

File and Directory Management

  • mv source destination renames a file (or moves it to a new directory).
  • cp source destination copies a file.
  • rm file removes a file. Directories must be empty before removal wth rm.

File Permissions

  • Permissions control how files can be accessed by users.
  • Use ls -l to view permissions: r (read), w (write), x (execute).
  • The first character in ls -l output indicates the file type: - (file), d (directory), s (symbolic link).
  • Permissions are grouped into user, group, and others, each with rwx settings.
  • chmod mode file changes file permissions; mode can be numeric (e.g., 744) or symbolic (e.g., a-w, u+x).
  • Numeric Mode: 7 (rwx), 4 (read), 2 (write), 1 (execute); calculate by summing permissions (e.g., r+w+x = 4+2+1 = 7).
  • Symbolic Mode: a (all), u (user), g (group), o (others); + (add permission), - (remove permission).

Ownership

  • chown user file changes the file's owner (requires sudo).
  • chown user:group file changes both owner and group.
  • The default group often matches the username in Ubuntu.

Superuser (Root) Privileges

  • sudo command executes a command with elevated (superuser) rights.
  • su starts an entire terminal session as the superuser.
  • exit returns the terminal to normal user privileges after using su.

Package Management

  • apt-get (Advanced Packaging Tool) manages packages (install/uninstall) in Debian/Ubuntu-based distributions.
  • Example: sudo apt-get install wireshark installs Wireshark.
  • yum (Yellowdog Updater, Modified) manages packages in Red Hat-based distributions, using RPM format.

Network Configuration

  • ip address displays network configuration details.
  • ip route shows the routing table.
  • sudo ip address add IP/mask dev adapter adds or modifies an IP address.

Disk Space

  • df (disk free) shows available disk space in 1K blocks by default.
  • df -h displays disk space in human-readable format (MB, GB).

Text Searching

  • grep pattern file searches a file for a specific text pattern.
  • Example: grep opened /var/log/auth.log finds lines containing "opened" in the authentication log.

Process Management

  • ps displays running processes for the current user.
  • ps -e shows all processes running on the system; pipe with more for easier viewing (ps -e | more).
  • top provides a dynamic, real-time view of processes, resource usage (CPU, memory), and system load (1, 5, 15-minute intervals); press q to quit.

File Finding

  • find path -name filename locates files by name.
  • Use . to start the search in the current directory.
  • Use wildcards (*) for pattern matching (e.g., find . -name "*.txt" finds all .txt files).

DNS Resolution

  • dig domain queries DNS servers to find IP addresses associated with a domain name.
  • It is not included with Windows by default, but can be downloaded from ISC.org.

File Concatenation

  • cat file1 file2 displays the content of both files on the screen.
  • cat file1 file2 > file3 combines the content of file1 and file2 into a new file3.

Text Editing

  • nano file opens a full-screen text editor; commonly pre-installed on Linux.
  • Ctrl+O saves the file.
  • Ctrl+X exits the editor.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

More Like This

Linux Command Line Basics
5 questions
Linux Commands Quiz
14 questions
Use Quizgecko on...
Browser
Browser