Mostrando postagens com marcador trainning. Mostrar todas as postagens
Mostrando postagens com marcador trainning. Mostrar todas as postagens

Breaking Linux files into pieces

 


  

  Simple Linux commands allow you to break up files and reassemble them as needed in order to accommodate size restrictions.



    Linux provide a very easy-to-use command for breaking files into pieces. This is something that you might need to do prior to uploading your files to some storage site that limits file sizes or emailing them as attachments. To split a file into pieces, you simply use the split command.

$ split filename

By default, the split command uses a very simple naming scheme. The file chunks will be named xaa, xab, xac, etc., and, presumably, if you break up a file that is sufficiently large, you might even get chunks named xza and xzz.dsc

You can also contribute to the file naming by providing a prefix. For example, to name all the pieces of your original file bigfile.xaa, bigfile.xab and so on, you would add your prefix to the end of your split command like so:

image

Note that a dot is added to the end of the prefix shown in the above command. Otherwise, the files would have names like bigfilexaa rather than bigfile.xaa.

Also, note that the split command does not remove your original file, just creates the chunks. If you want to specify the size of the file chunks, you can add that to your command using the -b option. For example:

split -b100M your_file

If you want your file to be split based on number of bytes, you can use the -b option. In this example, each file will 50b chuncks.

$ split --verbose -b50K zip zip.
creating file 'zip.aa'
creating file 'zip.ab'
creating file 'zip.ac'

If you need to reassemble your file from pieces on a remote site, you can do that fairly easily using a cat command like one of these:


cat x?? > original.file
cat log.?? > original.file


"Do you already know my Linux training !?" Available in portuguese only.


"Você já conhece meu treimanento de linux!?"

Neste treinamento vamos abordar de forma simples, rápida e sem “enrolação”  como instalar o Linux CentOS 8 utilizando o VirtualBox e a nuvem da Amazon AWS do zero.



What is Umask and how to setup - mini guide


What is Umask and how to setup


When user create a file or directory under Linux or UNIX, it is create it with a default set of permissions. In most case the system defaults may be open or relaxed for file sharing purpose. For example, if a text file has 666 permissions, it grants read and write permission to everyone. Similarly a directory with 777 permissions, grants read, write, and execute permission to everyone.

Default umask Value

    The user file-creation mode mask (umask) is use to determine the file permission for newly created files. It can be used to control the default file permission for new files. It is a four-digit octal number. A umask can be set or expressed using:

  • Symbolic values
  • Octal values

Procedure To Setup Default umask

You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:

# vi /etc/profile

OR

$ vi ~/.bashrc

Append/modify following line to setup a new umask:

umask 022

Save and close the file. Changes will take effect after next login only. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user’s environment at login).

Octal umask Mode 022 And 002

If the default settings are not changed, files are created with the access mode 666 and directories with 777. In this example:

  1. The default umask 002 used for normal user. With this mask default directory permissions are 775 and default file permissions are 664.

  2. The default umask for the root user is 022 result into default directory permissions are 755 and default file permissions are 644.

  3. For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666 (rw-rw-rw).

Then,

  1. A umask of 022 allows only you to write data, but anyone can read data.

  2. A umask of 077 is good for a completely private system. No other user can read or write your data if umask is set to 077.

A umask of 002 is good when you share data with other users in the same group. Members of your group can create and modify data files; those outside your group can read data file, but cannot modify it. Set your umask to 007 to completely exclude users who are not group members.

But, How Do I Calculate umasks?

The octal umasks are calculated via the bitwise AND of the unary complement of the argument using bitwise NOT. The octal notations are as follows:

  • Octal value : Permission

  • 0 : read, write and execute

  • 1 : read and write

  • 2 : read and execute

  • 3 : read only

  • 4 : write and execute

  • 5 : write only

  • 6 : execute only

  • 7 : no permissions

Now, you can use above table to calculate file permission. For example, if umask is set to 077, the permission can be calculated as follows:

To set the umask 077 type the following command at shell prompt:

$ umask 077
$ mkdir dir1
$ touch file
$ ls -ld dir1 file


Sample outputs:

drwx------ 2 vivek vivek 4096 2011-03-04 02:05 directoryx

-rw------- 1 vivek vivek    0 2011-03-04 02:05 filenumber1

Sample: Calculating The Final Permission For FILES

You can simply subtract the umask from the base permissions to determine the final permission for file as follows:

666 – 022 = 644

  • File base permissions : 666
  • umask value : 022
  • subtract to get permissions of new file (666-022) : 644 (rw-r–r–)

Sample: Calculating The Final Permission For DIRECTORIES

You can simply subtract the umask from the base permissions to determine the final permission for directory as follows:

777 – 022 = 755

  • Directory base permissions : 777
  • umask value : 022
  • Subtract to get permissions of new directory (777-022) : 755 (rwxr-xr-x)

How Do I Set umask Using Symbolic Values?

The following symbolic values are used:

  1. r : read

  2. w : write

  3. x : execute

  4. u : User ownership (user who owns the file)

  5. g : group ownership (the permissions granted to other users who are members of the file’s group)

  6. o : other ownership (the permissions granted to users that are in neither of the two preceding categories)

The following command will set umask to 077 i.e. a umask set to u=rwx,g=,o= will result in new files having the modes -rw——-, and new directories having the modes drwx——:

$ umask u=rwx,g=,o=
$ mkdir dir2
$ touch file2
$ ls -ld dir2 file2

Sample umask Values and File Creation Permissions
all = read, write and executable file permission

Limitations of the umask

  1. The umask command can restricts permissions.

  2. The umask command cannot grant extra permissions beyond what is specified by the program that creates the file or directory. If you need to make permission changes to existing file use the chmod command.

umask and level of security

The umask command be used for setting different security levels as follows:



"Você já conhece meu treimanento de linux!?"

Neste treinamento vamos abordar de forma simples, rápida e sem “enrolação”  como instalar o Linux CentOS 8 utilizando o VirtualBox e a nuvem da Amazon AWS do zero.

"Do you already know my Linux training !?" Available in portugues only.