Read Time:6 Minute, 6 Second

There’s a lot more to working with files on Linux than creating, listing and updating them. After all, files can be Linux commands (i.e., binaries), scripts, images, simple text files, pointers to other files or folders. You might remember the “everything is a file” description of Unix and Linux systems.

Even sockets and named pipes are files in their own way. Sometimes only the owner can see and use files, sometimes everyone can and sometimes select individuals will also have access. Here are some of the subtleties.

Listing files

Listing files on Linux is easy. You use the ls command. On the other hand, commands like ls, ls -l, ls -a and ls -ltr work very differently:

  • The ls command with no arguments simply lists file names
  • The ls -l (long listing) command adds file permissions
  • The ls -a command includes file names that start with dots (often referred to as “hidden files”)
  • The ls -ltr command shows files in old-to-new order while ls -lt lists the files in new-to-old order

Creating and updating files

If you want to create an empty file or update the timestamp on a file, use the touch command. Using touch -a will only change the access time. Using touch -d followed by a date (e.g., touch -d 20230101) will update the timestamp to the date specified:

$ ls -l message
-rw-rw-r--. 1 shs shs 39 Jun 12  2019 message
$ touch -d 20230101 message
$ ls -l message
-rw-rw-r--. 1 shs shs 39 Jan  1 00:00 message

The permissions string displayed for any file can be broken down as follows:

  • The first character represents the file type
  • Characters 2-4 show the owner’s permissions
  • Characters 5-7 show the group’s permissions
  • Characters 8-10 show the permissions for everyone else
  • Character 11 will be a “.” or a “+” (more on this below)

The listing below breaks some listings by fields.

Copyright © 2023 IDG Communications, Inc.


Source link

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Previous post Covid: Leftover swabs to be tested for other viruses in the UK — The Knowledge Pal
Next post Intel boosts VM security, guards against stack attacks in new Xeon release – The Knowledge Pal