Linux study session 2nd: File operation


Ancar Co., Ltd. holds a Linux study session once a week. I've been interested in writing programs so far, and I've been doing it mainly, so I'm missing out on basic knowledge of Linux .. I'm studying. For that reason, the content of the study session is for beginners.

This time, we held a study session on the theme of "file operations", so I would like to take up the parts that I learned especially about file operations.

File operations

Special directory symbol

Special directory symbols are provided to facilitate path specification.

I usually use /, ., .., etc. frequently. I especially learned about the ~- and ~ username options. This wasn't used at all on a daily basis.

** Move directory **

#Move by absolute specification
$ cd /home/onukichi/qiita/test1/

$ pwd

#Move to your home directory.[cd ~]But the same
$ cd

$ pwd

#Move to the previous directory. This is insanely convenient, why didn't I use it?
# [cd ~-]But the same
# cd -When, the destination directory is displayed.
$ cd -

$ pwd

#Designated user(onukichi)Go to your home directory
$ cd ~onukichi

$ pwd

View file contents

I used to use cat to casually display the contents of a file, but I can do various things by adding options.

$ cat test1
I'm Onukichi.

$ cat test2
I'm Kid.

#You can also concatenate files. Yeah, can you do that?..Never used
#Create test3 by concatenating test1 and test2 into files
$ cat test1 test2 > test3

#Display the contents of test3
$ cat test3
I'm Onukichi.
I'm Kid.

# 「-Display with line number in "n option"
$ cat -n test3
1  I'm Onukichi.
2  I'm Kid.

Move and rename files

I used to use the mv command a lot, but I found it convenient to be able to rename files and move multiple files as I moved.

$ ls 
test1  test2  test3

#Move one file to qiita directory, well this is basic
$ mv test1 ../../qiita/

#Yeah, it's been moved properly
$ ls /home/onukichi/qiita/

#You can change the name as you move. I didn't know this..
$ mv test2 ../../qiita/test2-1

#Move and check if it has been renamed.
$ ls /home/onukichi/qiita/
test1  test2-1

#Move multiple files, which is also very convenient..!
$ mv test1 test2-1 ../../qiita/text


The commands I picked up were the ones I used frequently on a daily basis, but I learned that by specifying options, I can operate files more conveniently.

I can't use any other commands as options, so I'd like to use them consciously.

Recommended Posts

Linux study session 2nd: File operation
Linux command [File operation]
Linux Study Session 1st: Virtual Console and File Manipulation
[Linux] Frequently used Linux commands (file operation)
[Linux] File and directory operation commands
Linux study session 3rd: File deletion prohibition setting and search function
Linux study notes
[Linux] File search
Read "Ordinary Linux Programming" at an in-house study session
Hack Linux file descriptors
Linux operation on Win10
Read "Ordinary Linux Programming" at an in-house study session ~ 10.11 Exercises ~
Device and Linux file system
Linux file and directory permissions
New Linux textbook (study notes)