Home Linux Basic Linux Commands: ls, touch, su, find, history

Basic Linux Commands: ls, touch, su, find, history

by Sean Ziegler

This post is an ongoing series of Linux commands helpful for developers and sysadmins alike. I do not intend this series to be a deep-dive into each command, we will take a quick look at each command, it’s usage, an example, and some common flags you might find useful.

#1 – ls

Usage: ls -flags [target]

Example: ls -la /var

Description: The ls commands lists all the files and folders in the target directory. If the target directory is blank, ls will list files in the current directory.

-a: include hidden files

-l: shows permissions, user:group, size, and last modified

#2 – touch

Usage: touch [filename]

Example: touch /var/log.txt

Description: The touch command creates files. There’s not much to this command, but if you want to create an empty file with as little effort as possible, touch is the way to go.

#3 – su

Usage: su [user]

Example: sudo postgres_user

Description: The su command allows a user to switch to the user account in the [user] argument. If you supply no user, the su command switches to the root user by default. sudo su - is an excellent way to get full root access, but beware, it can be dangerous.

#4 – find

Usage: find -option  [directory]

Example: find ~ -name "*.pem"

-name: matches files with specified filenames

-user: matches files owned by a specified user

-amin: file was accessed n minutes ago

-writable: file is writable for the current user

Description: The find command searches the starting point directory and all its subdirectories for files that match the -option flag. The find command can search your directory by name, user, access/modified time, permission options, and much more. The find command also supports wildcards and REGEXs for even more searching beauty.

#5  – history

Usage: history [n]

Example: history 50

Description: The history command shows the last n commands run in the shell. This command is awesome for re-running a long command you typed out by hand or copied. When you run the history command, you’ll get a numbered list of previously run commands. Enter a ! followed by the number of the command you want to run and it will run again in the shell.

You may also like

Leave a comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept