Bash Commands

Running Bash commands is quite easy. For example, you can verify the location of the current folder simply by entering the command pwd, which stands for print working directory, to print out the full path of the current working folder. Or you can see which files and subfolders are in the current folder by entering ls, which stands for list contents. Table 7-2 details some of the more common commands relating to files and folders (along with what they do).

Note

Throughout this book I use the terms folder and directory interchangeably. Directory was the initial term for a folder in Unix, whereas folder is the term more commonly used on desktop systems such as Ubuntu, but they both refer to the same thing.

Table 7-2. File and folder commands

Command

Arguments

Action

cat

file

Display the contents of file.

cd

folder

Change the working directory (or folder) to folder.

chmod

{various} fname

Change the file or folder fname’s permissions, according to the options in {various}.

cp

fname1 fname2

Copy the file or folder fname1 to fname2.

diff

file1 file2

Compare the contents of file1 with file2 and show the differences.

echo

text

Display the string text—generally used in shell scripts for providing feedback.

find

where -name what

Search the filesystem for filenames matching the string what, starting at the folder given in where.

grep

what where

Search the contents of the file or files supplied in where for occurrences of the string specified in what.

ls

 

List all files and folders in the current folder (except ...

Get Ubuntu: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.