0%

Linux Commands

File Commands

pwd

Print Working Directory. Find out the path of the current working directory.

cd

Change Directory. Change the current working directory

  • cd somewhere to go to that directory.
  • cd .. (with two dots) to move one directory up.
  • cd to go straight to the home folder.
  • cd- (with a hyphen) to move to your previous directory.

ls

List. View the contents of a directory.

  • ls will list current directory.
  • ls somewhere will list the directory named.
  • ls -R will list all the files in the sub-directories as well.
  • ls -a will show the hidden files.
  • ls -al will list the files and directories with detailed information like the permissions, size, owner, etc.

cat

Concatenate. List the contents of a file on the standard output (stdout).

  • cat filename (or filename1 filename2 filename3 …) will show content of given filename(s).
  • cat -n filename will show contents with line numbers.
  • cat > filename creates a new file
  • cat filename1 filename2 > filename3 joins two files (1 and 2) and stores the output of them in a new file (3)
  • to convert a file to upper or lower case use, cat filename | tr a-z A-Z > output.txt

cp

Copy. cp filename somewhere will copy file to the directory.

mv

Move files, and also can be used to rename files.

  • mv filename somewhere will move the file to the directory.
  • mv old_filename new_filename will rename the file with a new name.

mkdir

Make Directory.

  • mkdir somewhere
  • mkdir somewhere1/somewhere2/…/destination
  • mkdir somewhere1/destination/somewhere2

rmdir

Remove Directory. Only allows you to delete empty directories.

rm

Remove Files. rm -r alternative to rmdir.

touch

Create a blank new file.

locate

Locate a file. Use locate -i to be case-insensitive. locate A*B search files contain A and B.

find

Similar to locate. But you need to give it a directory.

grep

Search through all the text in a given file.

Higher

sudo

SuperUser Do.

df

Get a report on the system’s disk space usage, shown in percentage and KBs.

df -m to show in megabytes.

du

Disk Usage. type -h to get human readable statics.

View the first lines of any text file.

head -n somenumber filename.txt. View fist somenumber lines of file.

tail

View last lines.

diff

Difference. Compares the contents of two files line by line. After analyzing the files, it will output the lines that do not match.

tar

Archive multiple files into a tarball.

chmod

Change the read, write, and execute permissions of files and directories.

chown

Change or transfer the ownership of a file to the specified username.

jobs

Display all current jobs along with their statuses.

Kill

Send a certain signal to an app and instructs the app to terminate itself. Kill by its PID.

Reference

https://www.hostinger.com/tutorials/linux-commands