Kaigai Blog living abroad in my twenties

【My Study Note】The Command Line

Commands Programming

The Command Line

What you can do by learning Command Line

  • Creating New Directories
  • Creating New Files
  • Combining Directories
  • Copying and Moving Files around Different Directories
  • Searching through Files using Various Criteria and Keywords

What you can do with Advanced Command Line

  • Track Software
  • Access and Control Remote Servers
  • Search for Files using specific Criteria
  • Unzip Archives
  • Access Software Manuals and Display them in the Command Line
  • Install, Upgrade, and Uninstall Software
  • Mount and Unmount Computer Drives
  • Check Disk Space
  • Write Scripts to Automate Various Tasks
  • Control User Access to Files and Programs
  • Stop, Start and Restart Programs
  • Create Aliases of only a few characters long to Initiate Very Long Commands
  • Download Files from the Internet
  • Run Various Software
  • Run and Control Self-contained Virtual Software, which is also known as Containerization.

CD (Change Directory)

This is used to point our command line to a specific directory.

On Linux

// Pointing the command line to the desktop of your computer
cd ~/Desktop
//  You will move out of the current directory and back into the parent directory
cd ..

Touch

This makes a new file of whatever type you specify.

// Create the new file
touch example.txt

Mkdir

You can make new folders using the mkdir command.

// Create the new folder name "folderName"
mkdir folderName

History

To view a history of the most recently typed commands, you can use the history command.

history

Man (Short for Manual)

When called against a command, it will display a detailed manual of instructions for that given command. 

// This shows detailed manual of instructions for the list command "ls"
man ls

Flags

We can also use something called flags in conjunction with Unix commands. Flags are used to modify the behavior of a command. Think of them as options that can either change or extend the functionality of the given command. 

Ls

Ls is used to show the contents of the current working directory. Also, the ls command can accept many different types of flags that will change what is returned in the response.

ls -l

ls -l
  • List the File Out
  • List Order
  • Shows the Read or Write Permissions, Owners, and Groups it Belongs to

Ls -a

Ls -a

This will list all files and directories including hidden ones.

PWD(Print Working Directory)

This shows the full path of the current working directory.

cp

This command copies files or folders from one destination to another.

MV

This command moves files from one directory to another.

Cat

This command reads data from the file and gives their content as output.

cat example.txt

Wc

This commando shows the word count of a content.

wc file1.txt -w
// Return: 181 file1.txt

Pipes

A coding tool that allows the output of one command to be used as the input for a different command.

cat file1.txt | wc -w
// This returns the word count of file.txt
上のコードは、file1.txtのコンテンツを表示してその結果からワードカウントを行うコマンド

Less

Less is a command line utility that displays the contents of a file or a command output, one page at a time.

less names.txt