Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Advanced Use of "ls" in Linux

List Files Sorted by Time

You can list files sorted by time (newest first) using the -t option. Notice that the -t option is also support by hdfs dfs -ls.

ls -lht

Ignore Files

  1. You have to either enclose the pattern in quotes or escape the wildcard in patterns.

  2. Equivalent …

Sample Lines from a File Using Command Line

NOTE: the article talks about sampling "lines" rather than "records". If a records can occupy multiple lines, e.g., if any field contains a new line (\n), the following tutorial does not work and you have to fall back to more powerful tools such as Python or R.

Let's say …

Using Bash in Docker

If the docker container was started using /bin/bash (you can check using docker ps) command you can access it using attach.

docker attach container_name_or_id

If the docker container was started but not with /bin/bash, you have to create a bash instance inside the container using exec.

docker exec …