Categories
Tools

Useful Linux Commands — File Operations and Multiple Commands

Spread the love

Linux is an operating system that many developers will use.

Therefore, it’s a good idea to learn some Linux commands.

In this article, we’ll look at some useful Linux commands we should know.

less

The less command lets us show the content of a file.

The general syntax is:

less <filename>

We can navigate with arrow keys.

Spacebar and b navigates page by page.

/ lets us search for content.

? search backward.

F enters follow mode. When the file is changed, the changes are displayed live.

ctrl+c quits follow mode.

cp

cp lets us move files and folders.

For instance, we run:

cp foo bar

to copy foo to bar .

We can also use it to copy folders with the -r switch:

cp -r fruits cars

We move the fruits folder contents to cars .

mv

The mv command lets us move files and folders.

For instance, we run:

mv foo bar

to move foo to bar .

We can move files into a folder with:

mv grape banana fruits

We move the grape and banana files to the fruits folder.

ls

The ls command lets us list files and folders.

We can list the content of a given folder with:

ls /bin

We can add the a switch to show hidden files.

l shows files permissions, file and folder sizes, and modified date time.

We run ls -al to show all that info.

rmdir

The rmdir command lets us remove a folder.

We run:

rmdir fruits

to remove the fruits folder.

We can use it to remove multiple folders:

rmdir fruits cars

We remove the fruits and cars folders.

The folders we delete must be empty.

To delete non-empty folders, we run:

rm -rf fruits cars

-r means recursive and f means force.

pwd

pwd shows the current working directory.

cd

cd lets us change the current working directory.

For instance, we run:

cd fruits

to go to the fruits folder.

cd .. to move to the home folder.

cd ../cars moves to the parent folder of cars .

We can use absolute paths with cd , so we run cd /etc to go to the /etc folder.

mkdir

mkdir lets us create a folder.

For instance, we run:

mkdir cars

to create a cars folder in the current working directory.

And we run:

mkdir dogs cars

to create the dogs and cars folders.

We can create multiple nested folders with the -p switch:

mkdir -p fruits/apples

!!

!! lets us run the last command.

; / && / &

; lets us run one command after the other like:

ls; pwd

&& runs multiple commands but the ones on the right won’t run if the left one fails.

& lets us run multiple commands in parallel instead of waiting for the current one to finish before running the next one.

Conclusion

We can run commands to show file content and run multiple commands with some operators with Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *