YYisak
Published on

Linux Commands

Authors

Introduction

Linux is a an operating system that offers flexibility and control. Whether you're a system administrator or a developer, knowing your way around the Linux command line can be very beneficial. In this post, I'll cover some Linux commands that you can use to navigate the file system and more.

Definitions and Tools

Linux is a family of open-source Unix-like operating systems based on the Linux kernel. It's widely used in servers, desktops, and embedded systems.

Command Line Interface (CLI) is a text-based interface used to interact with a computer system. It allows users to execute commands by typing them directly into the terminal.

Shell is a program that interprets commands and acts as an intermediary between the user and the operating system. It's the command line interface to Linux.

Kernel is the core component of an operating system. It manages the system's resources and provides the lowest-level abstraction layer for resources.

Terminal is a program that allows you to interact with the shell. It provides a text-based interface for running commands.

zsh is a shell designed for interactive use, although it is also a scripting language. It's an extended Bourne shell.

Commands

Here are some Linux commands that you can use to navigate the file system and more.

Note that this is not an exhaustive list. Some commands options and usage may not be listed here, may not be correct and may also depend on the Linux distribution you are using.

Commands for getting help

man

The man command is used to display the manual page for a given command.

usage
man [options] command

--help

Commands may support the --help option to display information about how to use the command.

usage
command --help

whatis

The whatis command is used to display a one-line description of a command.

usage
whatis [options] keyword

pwd

The pwd command stands for "print working directory". It displays the current working directory.

usage
pwd [options]

ls

The ls command lists the files and directories in a directory.

usage
ls [options] [directory]

Options

  • -l: Long listing format
  • -a: Include hidden files
  • -h: Human-readable sizes
zsh
ls -lh

cd

The cd command is used to change directories. You can use it to navigate to a different directory.

usage
cd [options] [directory]

mkdir

The mkdir command is used to create a new directory.

usage
mkdir [options] directory

Options

  • -p: Create parent directories if they don't exist
  • -v: Print a message for each created directory

rmdir

The rmdir command is used to remove empty directories.

usage
rmdir [options] directory

rm

The rm command is used to remove files and directories.

usage
rm [options] [file]

Options

  • -r: Recursively remove directories and their contents
  • -f: Force removal without confirmation

cp

The cp command is used to copy files and directories.

usage
cp [options] source destination

Options

  • -r: Copy directories recursively
  • -i: Prompt before overwriting
zsh
cp -r sourcedir destdir

mv

The mv command is used to move files and directories.

usage
mv [options] source destination
  • We can also rename files using mv
zsh
mv oldfile newfile

touch

The touch command is used to create an empty file.

usage
touch [options] filename

Other commands

clear

The clear command is used to clear the terminal screen.

usage
clear [options] [terminal type]

cat

The cat command is used to concatenate and display the content of files.

usage
cat [options] [file]

grep

The grep command is used to search for patterns in files.

usage
grep [options] pattern [file]

pattern

  • .: Any single character
  • ^: Start of a line
  • $: End of a line
  • *: Zero or more occurrences
  • []: Any one of the characters inside the brackets
  • [^]: Any character not inside the brackets

find

The find command is used to search for files and directories in a directory hierarchy.

usage
find [options] [path] [expression]

Options

  • -name: Search for files with a specific name
  • -type: Search for files of a specific type (f: file, d: directory)
  • -exec: Execute a command on the found files
zsh
find . -name "*.txt"

chmod

The chmod command is used to change the permissions of files and directories.

usage
chmod [options] mode file

mode

  • u: User
  • g: Group
  • o: Others
  • a: All
  • +: Add permission
  • -: Remove permission
  • =: Set permission
zsh
chmod u+x file

less and more

The less and more commands are used to view the contents of a file one page at a time. The less command allows both forward and backward navigation.

usage
less file
more file

Bonus Content

The >> and > operators

The >> and > called the output redirection operators are used to redirect output to a file. They are used to save the output of a command to a file instead of displaying it on the terminal

usage
command >> file
command > file

>>

  • Appends output to the end of a file
  • Creates a new file if it doesn't exist
  • Preserves the existing content of the file

>

  • Redirects output to a file
  • Creates a new file if it doesn't exist
  • Overwrites the existing content of the file
zsh
echo "Hello, World!" > hello.txt

The | operator

The | operator is called a pipe. It is used to combine two or more commands together. It takes the output of one command and passes it as input to another command.

usage
command1 | command2

Conclusion

These are some Linux commands that you can use to interact with the system. I encourage you to explore more commands and experiment with them. Happy learning! 🐧