• Test whether a file or directory exist in shell

    How to test whether a file exist in shell on Linux? We can use the test command to check file types and whether it exits.

    How to test whether a path is a regular file in shell on Linux

    We can use the following command to test whether a path is a regular file and exist.

    How to test whether a path is a folder in shell

    Using the following command, we can test whether a path is a folder in shell on linux.

    How to test whether a file is a symbolic link on linux?

    [Read More...]
  • tar all the files under a directory on linux

    We often need to tar all the files under a directory into a zip file.  This post gives two examples to show how to tar all the contents under a directory into a tgz file. 

    Suppose we have directory structures like

    By running the following command, we can tar all the files of my_folder into the tgz file.

    However, you will find that you actually include the my_folder in the zip file. The structure of the tgz file will looks like this.

    What if you want the file structures like this:

    Two methods tar all the files under a directory into a tgz  file

    You can use the following command to include only the files under my_folder to the zip file:

    Using the -C option to tar all the files under a directory into a tgz file

    You can also using the -C option to include all the files under your directory into a zip file:

    The -C my_folder tells tar to change the current directory to my_folder,

    [Read More...]