10 Useful Unix Terminal Commands

10 Useful Terminal Commands for Web Developer

Written by Achmad Rizal Muttaqin on Wednesday January 20, 2016
Categories: tutorial, programming, story - Tags: comestoarra, linux, ubuntu, terminal - Comments
Achmad Rizal Muttaqin

Hi Folks, as a new web developer, I am going to share my experience about developing web on Unix (precisely Unix-like, Ubuntu Linux) Platform. Things that I like about developing web on Ubuntu are the command line utilities that are powerful and useful for many things. So, I am going to share some useful (at least for me) terminal command on Ubuntu.

  1. ls, ll

    ls command is mainly used to list contents of a directory. But for me, ls command is usually used to see modes and owner rather than just list of contents of a directory. This can be done by appending -la options to ls command

    File and directory modes are located on the most left side of the result. You can read more about file and directory mode here. And for bash Ubuntu users like me, there is ll command, an alias for command ls -la. This command is usually available by default, if it is not, it can be added to .bashrc file using this command echo "alias ll='ls -la'" >> ~/.bashrc

  2. chmod, chown

    chmod command is used to change file and directory mode. Commonly used example of this command is chmod 755 file_name or chmod -R 755 directory_name. The first command will make file_name has file mode of 755 which means the owner has full access, users with the specified group has read and execute access, and other users also has read and execute access. The numbers are binary representation of mode where the combinations as follows : Read (r) = 4, Write (w) = 2, and Execute (x) = 1. You can read more about file and directory mode here. And the second command will do same thing but recursively.

    chown command is used to change the owner of a file or directory. Unlike chmod command, this command usually need root access (ie. sudo for Ubuntu). Commonly used example of this command is chown user[:group] file_name or chown -R user[:group] directory_name.

  3. scp [options]

    scp command is used to transfer files between hosts on a network. Commonly used options for this command are : -r used to recursively copy a directory, -p used to preserve modification time, access time, and modes from the original file, and -i used when connecting to remote host while using key authentication. So the example command would be scp -rpi identity_file directory_name [email protected]:remote_directory_name

  4. ssh-keygen

    ssh-keygen command is used to create public - private key pair for ssh authentication. SSH key authentication is usually used to do password-less SSH connection

  5. ssh

    ssh command is used to log into a remote machine and execute remote commands. ssh command can also forward TCP ports over the secure channel. One example of this command is that it can forward MySQL service from remote host so that it can appear as local service. The example command would be ssh -fNL 7777:localhost:3306 [email protected] where -f tells ssh to go background, -N tells ssh to not execute any command, and -L tells ssh to forward port 3306 on localhost at cbn-dev.tk (ie. MySQL service) to port 7777 localhost at local machine. You can read more about ssh here.

  6. tar

    tar command is used to do archiving tasks. Together with ssh command, it can be used to transfer files over network in more efficient way than scp command. Example command is tar -czf - -C /path/to/somedir ./directorytotransfer | ssh [email protected] 'tar -xzf - -C /path/to/somedir'

  7. find

    find command is used to do searching tasks (ie. finding files or directory with specified criteria). It also can execute command against the list of its result. One example is delete all cache files (files with .cache extension) from website project. So the example command would be find /path/to/somedir -name "*.cache" -exec rm -v {} \;

  8. sed

    sed is a stream editor. A stream editor is used to perform basic text transformation on an input stream. sed can be used to do search and replace function on file(s). One of sed usage example is combining it with find command to build command to find some files and replace some specified text inside them. Example command is find /path/to/somedir -type f -exec sed -i -e 's/find_pattern/replace_with/' {} \;

  9. grep

    grep command is used to search pattern on a file or standard input (stdin). One of grep usage is that it can search for a pattern on bash history. This can be done by executing command history | grep "pattern" or grep "pattern" < ~/.bash_history

  10. sshfs

    sshfs is a tool to mount remote directory over SSH protocol so that remote directory will appear as local directory. This tool is usually not installed by default, but it always can be added by executing command apt-get install sshfs (for Ubuntu or Debian based system). One example of this command is sshfs [email protected]:remote_directory local_directory

That is all, Folks. If you have any thoughts, please let me know by leaving comment below. Cheers !!!

comments powered by Disqus

— Copyright © 2020 PT. Comestoarra Bentarra Noesantarra —