Use this tag for questions about file management and operations on files.

learn more… | top users | synonyms (1)

3
votes
2answers
870 views

Concatenate specific files into one single file

In a folder containing X files, I need to concatenate Y files (where X > Y) together into a single text file. I have the filenames (of Y files) that I need to concatenate. Can anyone please help me ...
9
votes
1answer
3k views

Why can't I have a folder and a file with the same name?

I've never had this problem before, but for some reason, I can't rename my folder to packages/. This is the structure: root - packages_old/ - packages When I try to rename the folder with ...
8
votes
1answer
6k views

Group within group file permissions

I tried finding this on here, but couldn't so sorry if it's a duplicate. Say I have 2 groups and a user: group1, group2, user1 with the following structure: group1 is a member of group 2, user1 is a ...
8
votes
4answers
3k views

How are directories implemented in Unix filesystems?

My question is how directories are implemented? I can believe a data structure like a variable e.g. table, array or similar. Since UNIX is Open Source I can look in the source what the program does ...
4
votes
3answers
2k views

granting write permissions to a group to a folder

How can I grant write permission to 1 group ? I have 2 users (alex and ben). alex is member of group alex and of group consult. ben is member of group ben and of group consult. I want to grant read ...
4
votes
2answers
535 views

List files created on Sundays

How do I list/find all the files created on Sundays or Mondays? How do I use the date parameter to display them? Something like : ls -f date + %a or find -type f | date +%A or find -type f ...
3
votes
1answer
302 views

How does the Linux file structure work?

I see the different folders bin, dev, mnt, proc, srv, sys, etc. What are the properties of all these different folders? What are there purposes? Are there files in some of them that I should not ...
8
votes
3answers
3k views

How to remove only the content of directories?

I'm in a folder: /var/myfolder. Inside there are some other folders like: /var/myfolder/A/ /var/myfolder/B/ `/var/myfolder/C/ etc. Inside each there are some files with random names. How do I ...
6
votes
3answers
193 views

Find the top 50 directories containing the most files/directories in their first level?

How can I use find to generate a list of directories which contain the most numbers of files. I'd like the list to be from highest to lowest. I'd only like the listing to go 1 level deep, and I'd ...
6
votes
5answers
1k views

Find images by size: find / file / awk

I've been trying to find png image files a certain height (over 500px). I know that file will return image dimensions. Example: $ file TestImg1a.png TestImg1a.png: PNG image data, 764 x 200, ...
4
votes
2answers
559 views

Local Account Creation Date

For compliance purposes there is the need to fetch information regarding local (user and non-user) accounts creation date on UNIX machines. Is there any way (even if it's not the most reliable or ...
4
votes
1answer
164 views

When was file created [duplicate]

How can i see when a file was created. I have looked at man page ls -lc is for last modification of file status ls -lu for access time ls -l not exactly indicated which time, last changed? I ...
4
votes
2answers
205 views

How to delete a directory automatically when an executable is killed

Quite often we run an executable that needs to write / read some temporary files. We usually create a temporary directory, run the executable there, and delete the directory when the script is done. ...
4
votes
4answers
13k views

Linux file access monitoring

Is there any way in unix to find out who accessed certain file in last 1 week? It may be user or some script ftp it to some other place. Can I get a list of user name who accessed certain file? How ...
3
votes
2answers
139 views

How can I monitor a file that fully recreates during its run?

This is a follow-up question of Why are some file changes not shown in tail -f? With the use of capital F: tail -F I can monitor the output of tail -F ~/.mysql_history from the manual: ...
3
votes
1answer
949 views

Can't rename a directory that I own

I have a directory with a big load of sub directories. I own all of them, and the permissions are all 777. pascal@azazel /box $ ls -al total 147872 drwxr-xr-x 293 root root 12288 aoû 22 19:44 ...
2
votes
4answers
108 views

Can a running script identify the logging context?

Let us say I redirect the STDOUT, STDERR of a program to files. ./script.sh 1> output.log 2> error.log Can the running program find this out i.e. know the paths to these files?
2
votes
3answers
77 views

How to get a list of applications associated with a file using command line

File associations usually are made in the desktop environment, but how to get a list of applications associated with a file using command line? Something like: $ getassoc foo.pdf <CR> $ ...
2
votes
5answers
4k views

Get the newest file from directory structure year/month/date/time

I store backups of databases in a directory structure year/month/day/time/backup_name an example would be basics_mini/2012/11/05/012232/RATIONAL.0.db2inst1.NODE0000.20110505004037.001 ...
2
votes
2answers
632 views

How do I output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices

I am having trouble knowing how to output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices.
2
votes
2answers
121 views

What file system is my file on? [duplicate]

How do I figure out which file system a given file/directory is located on? (For example, I would like to know if the file/directory is a temporary file in RAM, or if it's stored on disk. And what ...
0
votes
1answer
370 views

Updating last modified time of a file

I have created a script to read 15 pcap files from a folder and merge then into one file using mergecap command. I want the merged file to have the creation time same as the first file of the 15 files ...
0
votes
1answer
105 views

How can number of subdirectories and files be determined from ls -ld command? [closed]

How can number of subdirectories and files be determined from the output of using ls -ld command? I realize that this command only lists the directories.
38
votes
5answers
22k views

How to remove duplicate lines inside a text file?

A huge (up to 2 GiB) text file of mine contains about 100 exact duplicates of every line in it (useless in my case, as the file is a CSV-like data table). What I need is to remove all the repetitions ...
40
votes
8answers
26k views

How can I edit multiple files in VIM?

I know I can open multiple files with vim by doing something like vim 2011-12*.log, but how can I switch between files and close the files one at a time? Also, how can I tell the file name of the ...
24
votes
3answers
11k views

Reading lines from a file with bash: for vs. while

I'm trying to read a text file and do something with each line, using a bash script. So, I have a list that looks like this: server1 server2 server3 server4 I thought I could loop over this using ...
28
votes
6answers
2k views

How does Linux choose which application to open a file?

If a file tells the OS its file format, how does the OS choose which application to open it by default? In Windows, is the association stored in the registry table? How does Linux choose which ...
17
votes
1answer
52k views

Where are Apache file access logs stored?

Does anyone know where file access logs are stored, so I can run a tail -f command in order to see who is accessing a particular file. I have XAMPP, which is an Apache server installed on my machine, ...
24
votes
3answers
8k views

Clone ownership and permissions from another file?

Is there a command or flag to clone the user/group ownership and permissions on a file from another file? To make the perms and ownership exactly "like" that of another file?
26
votes
2answers
1k views

Why does a software package run just fine even when it is being upgraded?

Say I am running a software, and then I run package manager to upgrade the software, I notice that Linux does not bring down the running process for package upgrade - it is still running fine. How ...
19
votes
6answers
27k views

How do I can get the size of a file in a bash script?

How do I can get the size of a file in a bash script? How do I assign this to a bash variable so I can use it later?
10
votes
2answers
5k views

Fastest way to concatenate files

I've got 10k+ files totaling over 20GB that I need to concatenate into one file. Is there a faster way than cat input_file* >> out ? The preferred way would be a bash command, Python is ...
10
votes
3answers
4k views

Pseudo files for temporary data

I often want to feed relatively short string data (could be several lines though) to commandline programs which accept only input from files (e.g. wdiff) in a repeated fashion. Sure I can create one ...
21
votes
8answers
24k views

How do I loop through only directories in bash?

I have a folder with some directories and some files (some are hidden, beginning with dot). for d in *; do echo $d done will loop through all files, but I want to loop only through directories. ...
20
votes
4answers
8k views

How to properly and easy configure `xdg-open` without any enviroment?

I'm using OpenBox window manager without any desktop enviroment. xdg-open behaves strangely. It opens everything with firefox. $ xdg-settings --list Known properties: default-web-browser ...
43
votes
3answers
32k views

How to tell gzip to keep original file?

I would like to compress a text file using gzip command line tool while keeping the original file. By default running the following command gzip file.txt results in modifying this file and renaming ...
15
votes
3answers
7k views

List the files accessed by a program

time is a brilliant command if you want to figure out how much CPU time a given command takes. I am looking for something similar that can list the files being accessed by a program and its children. ...
20
votes
2answers
2k views

How do I make a file NOT modifiable?

While logged in, I can do the following: mkdir foo touch foo/bar chmod 400 foo/bar chmod 500 foo Then I can open vim (not as root), edit bar, force a write with w!, and the file is modified! How ...
12
votes
3answers
3k views

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is ...
12
votes
2answers
3k views

recursive statistics on file types in directory?

I did a website scrape for a conversion project. I'd like to do some statistics on the types of files in there -- for instance, 400 .html files, 100 .gif, etc. What's an easy way to do this? It has to ...
7
votes
7answers
20k views

List only regular files (but not directories) in current directory

I can use ls -ld */ to list all the directory entries in the current directory. Is there a similarly easy way to just list all the regular files in the current directory? I know I can use find find . ...
7
votes
5answers
8k views

How to copy directories with preserving hardlinks?

How to move directories that have files in common from one to another partition ? Let's assume we have partition mounted on /mnt/X with directories sharing files with hardlinks. How to move such ...
7
votes
3answers
5k views

Quickly find which file(s) belongs to a specific inode number

I know of this command: find /path/to/mountpoint -inum <inode number> but it is a very slow search, I feel like there has to be a faster way to do this. Does anybody know a faster method?
15
votes
5answers
7k views

How can I do a “copy if changed” operation?

I would like to copy a set of files from directory A to directory B, with the caveat that if a file in directory A is identical to a file in directory B, that file should not be copied (and thus its ...
13
votes
2answers
501 views

Is that possible to integrate zip and tar.gz files as directory into the file system

I wonder if there is a way to integrate (it's a bit different from mounting, I think) compressed files as directories into the file system? E.g., one could download a compressed-file.tar.gz to his ...
10
votes
3answers
854 views

Open a text file and let it update itself

How can I open a text file and let it update itself? Similar to the way top works. I want to open a log file and watch it update itself on the fly. I have just tried: $ tail error.log But just ...
9
votes
2answers
7k views

how to output text to both screen and file inside a shell script?

Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file ...
12
votes
1answer
7k views

ls taking long time in small directory

Running Ubuntu, I open a terminal and do sudo bash cd / ls | head -n 1000 And predictably about 20 directories are returned. However, if I do an ls, and don't pipe it into anything, the ls just ...
7
votes
1answer
135 views

Normal looking text file, detected by file as ASCII Pascal program text

I have a "normal" looking text file (contains english sentences) which is getting detected by file command as ASCII Pascal program text. How does Pascal program text differentiate itself from normal ...
7
votes
4answers
2k views

List X random files from a directory

Is there a way to list a set of say, 30 random files from a directory using standard Linux commands? (in zsh) The top answer described here does not work for me (sort does not recognize the option ...