10 Linux commands to score 25 marks in System Commands OPPE

abbazs - Aug 23 - - Dev Community

Introduction

Here are the 10 commands that you can learn to score 25 marks: pwd, ls, cd, mkdir, chmod, chown, touch, ln, man, and rm. We'll explore their usage, options, and real-world applications to help you learn:

1. man (Manual)

The man command is your go-to resource for understanding all other Linux commands. It's indispensable for exam preparation and on-the-spot information retrieval. Remember that you can always use man command and help command during the exam in the vm.

Basic Usage

man [section] command_name
Enter fullscreen mode Exit fullscreen mode

Common Options

  • -f: Display a short description from the manual page
  • -k: Search the short descriptions for keywords

Example

$ man ls
# This opens the manual page for the ls command

$ man -k directory
mkdir (1)            - make directories
rmdir (1)            - remove empty directories
# ... (more results)
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Practice navigating man pages efficiently. Knowing how to quickly look up command options can save you time during the exam.

2. pwd (Print Working Directory)

The pwd command helps you identify your current location in the filesystem.

Basic Usage

pwd
Enter fullscreen mode Exit fullscreen mode

Options

  • -L: Print the logical working directory (default)
  • -P: Print the physical directory, without resolving symbolic links

Example

$ pwd
/home/user/documents
$ cd /var/www/html
$ pwd
/var/www/html
$ pwd -P  # Useful when working with symlinks
/var/www/html
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Be prepared to use pwd in scenarios involving directory navigation and symbolic links.

3. ls (List)

The ls command displays directory contents and file information.

Basic Usage

ls [options] [directory]
Enter fullscreen mode Exit fullscreen mode

Common Options

  • -l: Long format, showing detailed information
  • -a: Show all files, including hidden ones
  • -h: Human-readable file sizes
  • -R: Recursive listing

Example

$ ls -lah
total 32K
drwxr-xr-x 4 user user 4.0K Aug 24 10:00 .
drwxr-xr-x 3 user user 4.0K Aug 24 09:55 ..
-rw-r--r-- 1 user user  18K Aug 24 09:58 document.txt
drwxr-xr-x 2 user user 4.0K Aug 24 09:59 project1
drwxr-xr-x 2 user user 4.0K Aug 24 10:00 project2
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Practice combining options like ls -lah for comprehensive file listings, as exams often require interpreting detailed file information.

4. cd (Change Directory)

The cd command is used for navigating the filesystem.

Basic Usage

cd [directory]
Enter fullscreen mode Exit fullscreen mode

Special Directories

  • cd ..: Move to parent directory
  • cd ~ or cd: Move to home directory
  • cd -: Move to previous directory

Example

$ pwd
/home/user
$ cd documents/projects
$ pwd
/home/user/documents/projects
$ cd ../..
$ pwd
/home/user
$ cd -
$ pwd
/home/user/documents/projects
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Practice navigating quickly between system directories and your home directory, as this is often part of multi-step exam questions.

5. mkdir (Make Directory)

The mkdir command creates new directories.

Basic Usage

mkdir [options] directory_name
Enter fullscreen mode Exit fullscreen mode

Options

  • -p: Create parent directories as needed
  • -v: Print a message for each created directory

Example

$ mkdir -p projects/{web,mobile}/{src,tests,docs}
$ tree projects
projects
├── mobile
│   ├── docs
│   ├── src
│   └── tests
└── web
    ├── docs
    ├── src
    └── tests

8 directories, 0 files
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Master the use of -p for creating nested directories, as this can save time in complex directory creation scenarios.

6. chmod (Change Mode)

The chmod command changes file permissions.

Basic Usage

chmod [options] mode file
Enter fullscreen mode Exit fullscreen mode

Understanding Permissions

  • Read (r): 4
  • Write (w): 2
  • Execute (x): 1

Example

$ ls -l script.sh
-rw-r--r-- 1 user user 234 Aug 24 09:57 script.sh
$ chmod 755 script.sh
$ ls -l script.sh
-rwxr-xr-x 1 user user 234 Aug 24 09:57 script.sh
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Practice both numeric (755) and symbolic (u+x) modes for changing permissions, as exams may require you to use both formats.

7. chown (Change Owner)

The chown command changes file ownership.

Basic Usage

chown [options] user[:group] file
Enter fullscreen mode Exit fullscreen mode

Options

  • -R: Change ownership recursively

Example

$ ls -l data.txt
-rw-r--r-- 1 user user 1234 Aug 24 10:10 data.txt
$ sudo chown root:admin data.txt
$ ls -l data.txt
-rw-r--r-- 1 root admin 1234 Aug 24 10:10 data.txt
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Understand the implications of changing ownership, especially in scenarios involving system files or multi-user environments.

8. touch

The touch command creates empty files or updates file timestamps.

Basic Usage

touch [options] file_name
Enter fullscreen mode Exit fullscreen mode

Options

  • -c: Do not create any files
  • -t: Use specific time instead of current time

Example

$ touch newfile.txt
$ ls -l newfile.txt
-rw-r--r-- 1 user user 0 Aug 24 10:15 newfile.txt
$ touch -t 202108241020.00 oldfile.txt
$ ls -l oldfile.txt
-rw-r--r-- 1 user user 0 Aug 24 10:20 oldfile.txt
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Be prepared to use touch for creating placeholder files or updating file timestamps, which might be part of scripting or file management questions.

9. ln (Link)

The ln command creates links between files.

Basic Usage

ln [options] target link_name
Enter fullscreen mode Exit fullscreen mode

Options

  • -s: Create a symbolic (soft) link
  • -f: Force creation of link, overwriting existing destination file
  • -r: Create relative symbolic links

Example

$ echo "Original content" > original_file
$ ln original_file hardlink
$ ln -s original_file symlink
$ ls -li original_file hardlink symlink
1234567 -rw-r--r-- 2 user user 17 Aug 24 10:30 hardlink
1234567 -rw-r--r-- 2 user user 17 Aug 24 10:30 original_file
1234568 lrwxrwxrwx 1 user user 13 Aug 24 10:30 symlink -> original_file
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Understand the differences between hard and symbolic links, as exam questions may test your knowledge on their behavior and use cases.

10. rm (Remove)

The rm command removes files and directories. Use with caution!

Basic Usage

rm [options] file
Enter fullscreen mode Exit fullscreen mode

Options

  • -r: Remove directories and their contents recursively
  • -f: Force removal without prompting
  • -i: Prompt before every removal

Example

$ ls
file1.txt file2.txt olddir
$ rm file1.txt
$ rm -r olddir
$ ls
file2.txt
Enter fullscreen mode Exit fullscreen mode

Exam Tip: Be cautious with rm -rf in exams. Understand its power and when it's appropriate to use.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player