Linux - File

Bash Liste Des Attaques Ovh


Linux file management



A full stop '.' before the name of the file makes it a hidden file. Example '.bash'

Sh - Hidden files


See Linux - Stat (File status)



Filename and extension

Using Parameters Expansion Removal

fileFullName=$(basename "$filePath")
# or

parent directory

  • From a path string where the file does not exist
echo ${VAR%/*}

  • dirname returns the first parent of an existing path file.
dirname "dir/file"

File Permission

Linux - File/Folder Permissions - Access Control List ( ACL ) - Posix Model

File exists

if [ ! -f $PATH ]; then
    echo "File $PATH not found!"

Absolute path

ABSOLUTE_PATH=$(realpath "${FILE_NAME}")


with Linux - ls (List directory content)

ls -lh myFile | awk '{ print $5 }'


  • -lh shows a human readable size
  • an awk will extract the 5de column of the ls output

Monitoring the size of a (log) file


# the program that run
# the log of the progam
# Don't touch below, the program
while kill -0 $(pgrep ${program}) 2> /dev/null; do
    count=$(( $count + 1 ))
	size=$(ls -lh ${logfile} | awk '{ print $5 }')
    echo "${count} - Process is running and the log is ${size}"
    sleep 10
echo "${count} - Process has exited"


cmp --silent $old $new || echo "files are different"
cmp -b $old $new 

See also : diff


diff file1 file2 | cat -t


  • ^M for CR,
  • ^I for tab

See also: comparison

Filter a list of files ?

This command below gives you all files in the current directory which begin by elfutils

dir | grep -i elfutils

  • find can do it recursviely

Remove a file?

Permission: In UNIX and Linux, the ability to remove a file is determined by the access bits of parent directory

chmod 777 .
chown hi-adm:hi-adm .

With the command rm


  • Basic
rm filename.extension
  • Prompts for confirmation before removing a file
rm -i filename.extension
  • Force removal of the file regardless of it bieng write-protected or open
rm -f filename.extension
  • Remove files recursively in 'directory'
rm -r directory

More … perform the man commando

man rm

Copy 1 or multiple file

cp - Copy one or more files to another location.


  • Copy of a directory with resistivity:
cp -r dirtocopy newdir
  • Copy two files
cp myFile1.txt myFile2.txt myDirDestination
  • Copy all files of directory
cp * myDirDestination
# or
cp /myDirSource/* /myDirDestination
  • Copy all txt files (with a pattern)
cp *.txt myDirDestination

Move / Rename

  • mv - Moves or renames file


mv file.log file.$(date "+%Y.%m.%d-%H.%M.%S").log


cat file1 file2 > finalFile

# example with cert
cat first_cert.pem second_cert.pem > combined_cert.pem


See the content

Search a file by name

  • locate - List files that match a pattern.

Locate all file with a regular expression. In this example all file which begin with sp and end up with the extension msb.

locate -r "sp.*\.msb"
find /my/directory -name myFile.extension
find /my/directory -name globPattern

Search files based on time

touch -d '2011-12-31 10:22' foo
find . -newer foo

See all other files in the time section of the find command

Search the content of files

Shell Data Processing - Global Regular Expression Print (GREP command) (line filtering, word search)

  • For the current directory .
grep -rn "string*" .

File Architecture (32 or 64 bit)

File Architecture

file fileName


file java
/bin/java: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped


OLDIFS=$IFS; IFS=$'\n'; 
filelines=`cat $filename`
for line in $filelines ; do
    echo $line

Executable Capability

A file may also be an executable one and it may got capabilities such as being able to take the port 80

On Linux, see:

  • setcap - set file capabilities.
sudo setcap 'cap_net_bind_service=+ep' /path/to/your/executable
  • getcap - get the file capabilities.
sudo getcap /path/to/your/executable


List of command

  • ls - List contents of a directory
  • which - Displays path to command
  • whereis - locate the binary, source, and manual page files for a command


Discover More
Bash Liste Des Attaques Ovh
Bash - Conditional Expression

A predicate or boolean expression is known in Bash as a Conditional Expression. It is a command that returns an exit status of 0 or 1. The conditional expression is part of the compound expression. ...
Bash Liste Des Attaques Ovh
Bash - For Statement

The for statement in bash forloop statements of Bash With a file. Locate returns a list of file in one line separated by a space. This code use then the loop array loop with the Bash version...
Characters - Newline - End of Line ( EOL ) - Line Separators - Line Break

To mark line endings in text files, the following characters are used: Unix/Linux file systems use newlines (\n). MacOS uses carriage-returns (\r). Windows uses a carriage-return followed by...
Bash Liste Des Attaques Ovh
Linux - How to edit a file?

To edit a file in the shell mode, you have to use an editor such as: emacs vi pico gedit nano Winscp To edit the file: To save the file: with pico type CTRL+O to save and CTRL+X to...
Deleted Open File
Linux - du (Disk Usage)

du is a disk usage tool that estimates file space usage by subfolder. It exists also as Technet edition Windows: cleanmgr.exe Free also the...
Bash Liste Des Attaques Ovh
Linux - find command

Search, print information and takes actions on files in a directory hierarchy. Find use stat to extract its information File Metadata Synbol Default Description '-H', '-L' and '-P' options control...
Bash Liste Des Attaques Ovh
Sh - Hidden files

Files which the name start with a dot, are hidden. You can see them with the “-a” option of the ls command.
Bash Liste Des Attaques Ovh
Sh - touch

Create a new file without content (an empty file).

Share this page:
Follow us:
Task Runner